Home > Back-end >  The tail of the interpolation this mistake how to solve?
The tail of the interpolation this mistake how to solve?

Time:09-24

# include & lt; Stdio. H>
# include & lt; Stdlib. H>

/* */node configuration
Struct Data
{int key;
The int data;
Struct Data * next;
};
Typedef struct Data Node;

/* the establishment of the list */
Node * createList (Node * head) {
,20,30,40,50 int a [5]={10};
Int k [5]={1, 2, 3, 4, 5};
Node * newp=NULL;
for (int i=0; I & lt; 5; I++)
{
Newp=malloc (sizeof (Node));
Newp - & gt; Data=https://bbs.csdn.net/topics/a [I];
Newp - & gt; The key [I]=k;
Newp - & gt; Next=NULL;

Newp - & gt; Next=head;
The head=newp;
}
Return the head;
}

/* find */
Node * findList (Node * head, int k) {
While (the head!=NULL)
{
If (the head - & gt; Key==k)
{
Printf ("=================\ n ");
Printf (" % d ", the head - & gt; Key);
Printf (" % d \ n ", the head - & gt; The data);
Printf ("=================\ n ");
Return the head;
} the else
{
The head=head - & gt; Next;
}
}
return NULL;
}



Print/* */
Void printList (Node * head) {
While (the head!=NULL)
{
Printf (" % d ", the head - & gt; Key);
Printf (" % d \ n ", the head - & gt; The data);
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - \ n ");
The head=head - & gt; Next;
}
return ;

}

/* */release
Void freeList (Node * head) {
Node * temp=head;
While (the head!=NULL)
{
The head=head - & gt; Next;
Free (temp);
Temp=head;
}
return ;
}
/* head */
Node * inserNode2head (Node * head, Node * newp) {
Newp - & gt; Next=head;
The head=newp;
Return the head;
}

/* l end inserted */
Void inserNodeAfter (Node * head, int k, Node * newp) {
The Node * KP=findList (head, k);
if(! KP) {
Printf (" key not found! \n");
return ;
}
Newp - & gt; Next=KP - & gt; Next;
KP - & gt; Next=newp;
return ;
}
Int main (int arg c, char * const argv [])
{
The head Node *=NULL;
Node * newp=NULL;
Newp=malloc (sizeof (Node));
Newp - & gt; Key=12;
Newp - & gt; Data=https://bbs.csdn.net/topics/12;
Newp - & gt; Next=NULL;
The head=createList (head);

InserNodeAfter (head, 2, newp);

The head=inserNode2head (head, newp);
Printf (" ______________________ \ n ");
PrintList (head);
FindList (head, 3);

FreeList (head);
return 0;
}

CodePudding user response:

Print the list to find the key value node position from the beginning to repeat print

CodePudding user response:

Newp - & gt; Next=NULL;===="" if it's head, there should be a head - & gt; Next=NULL;
Newp - & gt; Next=head;===& gt;> If it is the tail plug here should be the sample head - & gt; Next=newp;
The head=newp;

Have you this list the problems
  • Related