Home > database >  Insert the second in a singly linked list singly linked lists
Insert the second in a singly linked list singly linked lists

Time:10-02

#include
#include
Typedef int DataType.
Typedef struct Node {
DataType data;
Struct Node * next;
} SLNode;
Int main () {
Int I, x, k, num1, num2, input1, input2.
SLNode * head1;
Head2 SLNode *;
SLNode * head3;
ListInitiate (& amp; Head1);
ListInitiate (& amp; Head2);
ListInitiate (& amp; Head3);
Printf (" input the first element of a singly linked list number: \ n ");
The scanf (" % d ", & amp; Num1);
Printf (" \ n input the first element of a singly linked list: \ n ");
for(i=0; iThe scanf (" % d ", & amp; Input1);
ListInsert (head1, I, input1);
}
Printf (" input the second number of elements in the singly linked lists: \ n ");
The scanf (" % d ", & amp; Num2);
Printf (" \ n input the second element of a singly linked list: \ n ");
for(i=0; iThe scanf (" % d ", & amp; Input2);
ListInsert (head2, I, input2);
}
Printf (" \ n input in the position of the first singly linked lists: \ n ");
The scanf (" % d ", & amp; K);
The List (head1, head2, head3, k);
for(i=0; iListGet (head3, I, & amp; X);
Printf (" % d ", x);
}
return 0;
}
//initialize
Void ListInitiate (SLNode * * head) {
* head=(SLNode *) malloc (sizeof (SLNode));
The head (*) - & gt; Next=NULL;
}
//the current element number
Int ListLength (SLNode * head) {
SLNode * p=head;
Int size=0;
While (p - & gt; Next!=NULL) {
P=p - & gt; Next;
Size++;
}
Return the size;
}
//insert
Int ListInsert (SLNode * head, int I, DataType x) {
SLNode * p * q;
int j;
P=the head;
J=1;
While (p - & gt; Next!=NULL& & JP=p - & gt; Next;
j++;
}
If (j!=I - 1) {
Printf (" insert element position error!" );
return 0;
}
Q=(SLNode *) malloc (sizeof (SLNode));
Q - & gt; data=https://bbs.csdn.net/topics/x;
Q - & gt; Next=p - & gt; Next;
P - & gt; Next=q;
return 1;
}
//remove
Int ListGet (SLNode * head, int I, DataType * x) {
SLNode * p;
int j;
P=the head;
J=1;
While (p - & gt; Next!=NULL& & JP=p - & gt; Next;
j++;
}
If (j! I)={
Printf (" remove the element position error!" );
return 0;
}
* x=p - & gt; The data;
return 1;
}
//a singly linked list to insert another
Int a List (SLNode * head1, SLNode * head2, SLNode * head3, int k) {
SLNode * p * q * m;
P=head1 - & gt; Next;
Q=head2 - & gt; Next;
M=head3;
Int a, x;
For (a=0; AM - & gt; Next=p;
P=p - & gt; Next;
M=m - & gt; Next;
}
For (int j=0; JM - & gt; Next=q;
Q=q - & gt; Next;
M=m - & gt; Next;
}
For (int n=0; NM - & gt; Next=p;
P=p - & gt; Next;
M=m - & gt; Next;
}
Without error, but results are not to come out, looked big solutions, why don't run out as a result, how to change

CodePudding user response:

What is the big bosses teach me thank you bosses
  • Related