Home > Back-end >  Bosses to help take a look at this c singly linked list data structure
Bosses to help take a look at this c singly linked list data structure

Time:10-20

#include
#include
#include
#include
Typedef int Elemtype;

Typedef struct List
{
Elemtype cur;
Struct List * next;
} sqlist, * Node;

Void Init_List (Node & amp; L, Elemtype & amp; N)
{
The Node s, k;
L=(Node) malloc (sizeof (sqlist));
L - & gt; Next=NULL;
Printf (" please create table length: \ n ");
The scanf (" % d ", & amp; n);
int i;

S=(Node) malloc (sizeof (sqlist));
S - & gt; Next=L - & gt; Next;

L - & gt; Next=s;
K=s;
for(i=0; i{

S=(Node) malloc (sizeof (sqlist));
K - & gt; Next=s;
K=s;
}
K - & gt; Next=NULL;
}
The Node Insert (Node & amp; L, k Node, the Node j)
{
L=(Node) malloc (sizeof (sqlist));
L - & gt; Next=NULL;
Printf (" start to merge \ n ");
The Node p, q, a, c, h.
K - & gt; Next=p;
Q=p;
J - & gt; Next=a;
C=a;
If (p - & gt; Cur> A - & gt; Cur) {L - & gt; Next=p; P=q - & gt; Next; Q=p; }
The else {L - & gt; Next=a; A=c - & gt; Next; C=a; }
H=L - & gt; Next;



while(p!=NULL& & a!=NULL)
{
Q=p - & gt; Next;
C=a - & gt; Next;
If (p - & gt; Cur> A - & gt; Cur) {h - & gt; Next=p; H=p; P=q; Q=p - & gt; Next; }
The else {h - & gt; Next=a; H=a; A=c. C=a - & gt; Next; }
}
Return (L);
}
Void the order (Node & amp; L)
{
The Node p, q, r;
Printf (" sort: \ n ");
P=L - & gt; Next;
Int t=0;
while(p!=NULL)
{
Q=p - & gt; Next;
R=q - & gt; Next;
while(q!=NULL)
{
If (p - & gt; Cur<=q - & gt; Cur) {t=q - & gt; A cur. Q - & gt; Cur=p - & gt; A cur. P - & gt; Cur=t; }
Q=r;
R=q - & gt; Next;
}

Q=p - & gt; Next;
P=q;
}
Printf (" \ n ");

}
Void distory (L)
{Node s;
While (s!=NULL)
{s=L - & gt; Next;
Free (L);
L=s; }
}
Void the output Node (L)
{
The Node s, j;
S=L - & gt; Next;
J=s;
Printf (" will get the result: \ n ");

While (s!=NULL) {printf (" % d \ n ", s - & gt; Cur); S=j - & gt; Next; J=s; }
}
Void the input Node (L)
{
The Node s, j;
Printf (" single table input values of cur: \ n ");
int x;
L - & gt; Next=s;
J=s;
While (s!=NULL)
{
The scanf (" % d ", & amp; X);
S - & gt; Cur=x;
J=s - & gt; Next;


S=j;
}


Printf (" input end \ n ");
}






Void main ()
{
The Node t, r, h;
Printf (" create two tables \ n ");
int k;
Init_List (t, k);
Init_List (r, k);
Input (t);
Input (r);


The order (t);
The order (r);
H=the Insert (h, t, r);
Printf (" finally get \ n ");
The output (h);
getchar();
getchar();
}
Run to the way, there is press any key to contine, don't know how to return a responsibility?

CodePudding user response:

 # include 
#include
#include
#include

Typedef int Elemtype;

Typedef struct List
{
Elemtype cur;
Struct List * next;
} sqlist, * Node;

Void Init_List (Node & amp; L, Elemtype & amp; N)
{
The Node s, k;
int i;

L=(Node) malloc (sizeof (sqlist));
L - & gt; Next=NULL;
Printf (" please create table length: \ n ");
The scanf (" % d ", & amp; n);

/*
S=(Node) malloc (sizeof (sqlist));
S - & gt; Next=L - & gt; Next;
*/

K=L;
for(i=0; i{

S=(Node) malloc (sizeof (sqlist));
K - & gt; Next=s;
K=s;
}
K - & gt; Next=NULL;
}
//the Node Insert (Node & amp; L, k Node, the Node j)
Node merge (Node & amp; L, Node a and Node b)
{
The Node p, q, s, t;
L=(Node) malloc (sizeof (sqlist));
L - & gt; Next=NULL;
Printf (" start to merge \ n ");

P=a - & gt; Next;
Q=b - & gt; Next;
S=L;
While (p & amp; & Q) {
If (p - & gt; Cur & lt; Q - & gt; Cur) {
S - & gt; Next=p;
S=p;
P=p - & gt; Next;
} else if (p - & gt; Cur & gt; Q - & gt; Cur) {
S - & gt; Next=q;
S=q;
Q=q - & gt; Next;
} else {
S - & gt; Next=p;
S=p;
T=q;
Q=q - & gt; Next;
P=p - & gt; Next;
Free (t);
}
}
S - & gt; Next=NULL;
If (p) {
S - & gt; Next=p;
}
If (q) {
S - & gt; Next=q;
}
A - & gt; Next=NULL;
B - & gt; Next=NULL;

Return the L;
/*
L=(Node) malloc (sizeof (sqlist));
L - & gt; Next=NULL;
Printf (" start to merge \ n ");
The Node p, q, a, c, h.
K - & gt; Next=p;
Q=p;
J - & gt; Next=a;
C=a;
If (p - & gt; Cur> A - & gt; Cur) {L - & gt; Next=p; P=q - & gt; Next; Q=p; }
The else {L - & gt; Next=a; A=c - & gt; Next; C=a; }
H=L - & gt; Next;



while(p!=NULL& & a!=NULL)
{
Q=p - & gt; Next;
C=a - & gt; Next;
If (p - & gt; Cur> A - & gt; Cur) {h - & gt; Next=p; H=p; P=q; Q=p - & gt; Next; }
The else {h - & gt; Next=a; H=a; A=c. C=a - & gt; Next; }
}
Return (L);
*/
}
Void the order (Node & amp; L)
{
The Node p, q, r;
Elemtype TMP.


P=L - & gt; Next;

Printf (" sort: \ n ");
While (p) {
Q=p - & gt; Next;

While (q) {
If (p - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related