Home > Back-end >  Bosses, help me singly linked lists to run the last little black window shut down automatically when
Bosses, help me singly linked lists to run the last little black window shut down automatically when

Time:09-16


/* # include & lt; Iostream. H> 
#include */
#include
#include
#include
#include
#include
#include

//define the type of node
Struct Node {
int data;
Node * next;
};

The Node Head;//head node
DLList Node * and * a * b * c.//the head pointer

Void init (Node * DLList);
Void the display (Node * DLList);
Int the insert (Node * DLList);
Void search (Node * DLList);
Void del (Node * DLList);
Void reverse (Node * DLList);//on the inverse set function
Void generateandmerge (Node * a, Node * b, Node * c);//generated two chain table and merge function
Int main ()
{
char choice;

DLList=& amp; The Head;//make the head pointer to head node
Head. Next=NULL;

While (1)
{
//system (" CLS ");
Printf (" \ n \ n \ n \ n ");
Printf (" \ t \ \ t singly linked lists operation n ");
Printf (" \ \ t t======================================");
Printf (" \ n \ n ");
Printf (" \ \ t t 1: initialize \ n ");
Printf (" \ \ t t 2: displays \ n ");
Printf (" \ \ t t 3: a single insert \ n ");
Printf (" \ \ t t 4: find \ n ");
Printf (" \ t \ t 5: delete \ n ");
Printf (" \ t \ t 6: in situ inverse set \ n ");
Printf (" \ t \ t 7: generates two lists and merge \ n ");
Printf (" \ t \ t 0: exit \ n ");
Printf (" \ n ");
Printf (" \ t \ t please select: ");

Choice=getch ();
//system (" CLS ");

The switch (choice)
{
Case '1' :
Init (DLList);
break;
Case '2' :
The display (DLList);
break;
Case '3' :
Insert (DLList);
break;
Case '4' :
Search (DLList);
break;
Case '5' :
Del (DLList);
break;
Case '6' :
Reverse (DLList);
break;
Case '7' :
Generateandmerge (a, b, c);
break;
Case '0' :
exit(0);
}
}
}

//public wait functions
Void wait ()
{
Printf (" \ n \ n press any key to continue ");
Getch ();
}

//screen, input from the keyboard linear table length and the random number seed, generate the DLList as head pointer specified length linear table
Void init (Node * DLList)//implement the establishment of a singly linked list
{
Int length;
The Node * p, * q;
While (1)
{
Printf (" input element number (0-10000) : ");
The scanf (" % d ", & amp; Length);
If (length & gt;=0 & amp; & Length & lt;
=10000)break;
printf("\n");
}

int i;
While (1)
{
Printf (" input random number seed (0-32767) : ");
The scanf (" % d ", & amp; I);
If (I & gt;=0 & amp; & I & lt;
=32767)break;
printf("\n");
}

//delete from the linear table and release the original node, making it a empty table
P=DLList;
While (p - & gt; Next!=NULL)
{
Q=p - & gt; next;
P - & gt; Next=q - & gt; next;
Free (q);
}

Srand (I);//the specified random number seed, the seeds of the same will produce the same data sequence
The rand ();

//insert length to the linear table a new node
For (int j=1; j<=length; J++)
{
P=new Node;
P - & gt; Next=DLList - & gt; next;
DLList - & gt; Next=p;
P - & gt; data=https://bbs.csdn.net/topics/rand () % 10000;
}
}

//in turn display on the screen for DLList head pointer all the elements and the number of elements of the linear table
//format should be easy to observe
//if you need to specify the width of the output, you can use the cout & lt; Void the display (Node * DLList)
{
//the Node * DLList;
//DLList=head; It has already been defined, defines redefine mistake will happen again here,
If (DLList==NULL)
{
Printf (" list is empty!" );
}
While (DLList)
{
Printf (" % d ", DLList - & gt; data);
DLList=DLList - & gt; next;
}
printf("\n");
Printf (" list finished output \ n ");
}

//screen prompts, an element from the keyboard input value, and then insert the new element to the DLList as head pointer at the end of the linear table!!
Int the insert (Node * DLList)
{int num.
Node * temp;
Printf (" please input a need to insert the element value: ");
The scanf (" % d ", & amp; Num);
If (NULL==DLList)
{
return 1;
}
//create a new node and determine whether to create success
Node * Node=(*) malloc (sizeof (Node)/sizeof (char));
If (NULL==node)
{
return 0;
}

//to node member variable assignment
Node - & gt; Data=https://bbs.csdn.net/topics/num;
Node - & gt; Next=NULL;

//the new node into the list of the last node
Node * TMP=DLList;
While (TMP - & gt; Next)
{
TMP=TMP - & gt; next;
}
//find the list of end node and end node to node
TMP - & gt; Next=node;


While (DLList)
{
Printf (" % d ", DLList - & gt; data);
DLList=DLList - & gt; next;
}
printf("\n");
Printf (" list finished output \ n ");
return 1;

}

//screen prompts, an element from the keyboard input values, the DLList as linear search this element in the table of the head pointer
Void search (Node * DLList)
{
Int e;
Printf (" please input a need to find the element value: ");
The scanf (" % d ", & amp; E);
Int I=1;
While (DLList!=NULL& & DLList - & gt; The data!=e)
{
DLList=DLList - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull