Home > Back-end >  Bosses to help look at what is going wrong
Bosses to help look at what is going wrong

Time:10-04


Suppose there is a cycle is greater than 1 the length of the list, and in the table is the headless nodes or headless pointer, the known p as a pointer to a node on the list, try to write algorithms in the list to delete a pointer p nodes of precursor,

Can run, the card in the output

# include & lt; stdio.h>
# include & lt; Stdlib. H>
# define MaxSize 100
Typedef int ElemType;
Struct node {
The int data;
Struct node * next;
}; Typedef struct node node;

NODE * init ()
{NODE * p;
P=(*) malloc (sizeof (NODE));
P - & gt; Next=p;
return p;
} NODE * createlist ()
{
The NODE * p, * L; int x;
P=the init ();
Printf (" please input a set of data to 1 to end the mark ");
The scanf (" % d ", & amp; X);
while(x!=1)
{
L=(*) malloc (sizeof (NODE));
L - & gt; data=https://bbs.csdn.net/topics/x; L -> next=p -> next; P -> next=L;
The scanf (" % d ", & amp; X);
}
} NODE * delprev (NODE * p)
{int n; Q, the NODE * * k * l; Q=p; Printf (" please enter p point value: ");
The scanf (" % d ", & amp; N);
While (q - & gt; Next - & gt; The data!=n)
{k=q; Q=q - & gt; Next;
}
L=q - & gt; Next;
K - & gt; Next=l;
Free (q);
Return (l);
}

Void print (NODE * L)
{
NODE * k;
K=L;
While (k - & gt; Next!=NULL)
{
Printf (" % d ", k - & gt; The data);
K=k - & gt; Next;
}
Printf (" % d ", k - & gt; The data);
}

Int main ()
{
The NODE * L, * p;
P=createlist ();
L=delprev (p);
Print (L);
}
  • Related