Home > Back-end >  The headless pointer circular linked list, delete a particular value node of the precursor. Infinite
The headless pointer circular linked list, delete a particular value node of the precursor. Infinite

Time:10-04

#include
#include
Struct node {
The int data;
struct node *next;
};
Typedef struct node node;

NODE * creat () {
int x;
The NODE * p, * s * r;
P=(*) malloc (sizeof (NODE));
S=p;
The scanf (" % d ", & amp; X);
P - & gt; data=https://bbs.csdn.net/topics/x;
while(x!=1)
{the scanf (" % d ", & amp; X);
R=(*) malloc (sizeof (NODE));
R - & gt; data=https://bbs.csdn.net/topics/x;
P - & gt; Next=r;
p=r;
}
P - & gt; Next=s;
The return (s);
}
NODE * shuchu (NODE * L)
{NODE * p;
P=L;
While (p)
{printf (" % d ", p - & gt; The data);
P=p - & gt; Next; }
}
NODE * delprev (NODE * p, int b) {

The NODE * L, * r * k;
L=p;

While (L - & gt; Next - & gt; The data!=b)
{r=L;
L=L - & gt; Next; }
K=L - & gt; Next;
R - & gt; Next=k;
Free (L);
Return (k);
}

Int main ()
{
int a;
The NODE * L, * p;

Printf (" new list \ n input values to end - 1: ");
P=creat ();
Printf (" the value of the specified node p: ");
The scanf (" % d ", & amp; a);
L=delprev (p, a);
Shuchu (L);
}



The headless pointer circular linked list, delete a particular value of node's precursor,
Delete properly, but turned into a infinite loop


CodePudding user response:

 # include 
#include

Struct node {
The int data;
struct node *next;
};

Typedef struct node node;

NODE * creat ()
{
int x;
The NODE * p, * s * r;
P=(*) malloc (sizeof (NODE));
S=p;
The scanf (" % d ", & amp; X);
P - & gt; Data=https://bbs.csdn.net/topics/x;
//while (x!=1)
While (1)
{
The scanf (" % d ", & amp; X);
If (x==1)
break;
R=(*) malloc (sizeof (NODE));
R - & gt; Data=https://bbs.csdn.net/topics/x;
P - & gt; Next=r;
P=r;
}
P - & gt; Next=s;

The return (s);
}

//the NODE * shuchu (NODE * L)
Void shuchu (NODE * L)
{
NODE * p;

P=L;
//while (p) {
While (p - & gt; Next!=L) {
Printf (" % d ", p - & gt; The data);
P=p - & gt; Next;
}
Printf (" % d ", p - & gt; The data);
}

NODE * delprev (NODE * p, int b) {

The NODE * L, * r * k;
L=p;

While (L - & gt; Next - & gt; The data!=b)
{r=L;
L=L - & gt; Next; }
K=L - & gt; Next;
R - & gt; Next=k;
Free (L);
Return (k);
}

Int main ()
{
int a;
The NODE * L, * p;

Printf (" new list \ n input values to end - 1: ");
P=creat ();
Shuchu (p);
Printf (" the value of the specified node p: ");
The scanf (" % d ", & amp; a);
L=delprev (p, a);
Shuchu (L);
}

For your reference ~

The original poster is circular linked list, but there is no special handling shuchu function, so it is infinite loop,

The modified elsewhere, for your reference

CodePudding user response:

The
reference 1/f, confident boy reply:
 # include 
#include

Struct node {
The int data;
struct node *next;
};

Typedef struct node node;

NODE * creat ()
{
int x;
The NODE * p, * s * r;
P=(*) malloc (sizeof (NODE));
S=p;
The scanf (" % d ", & amp; X);
P - & gt; Data=https://bbs.csdn.net/topics/x;
//while (x!=1)
While (1)
{
The scanf (" % d ", & amp; X);
If (x==1)
break;
R=(*) malloc (sizeof (NODE));
R - & gt; Data=https://bbs.csdn.net/topics/x;
P - & gt; Next=r;
P=r;
}
P - & gt; Next=s;

The return (s);
}

//the NODE * shuchu (NODE * L)
Void shuchu (NODE * L)
{
NODE * p;

P=L;
//while (p) {
While (p - & gt; Next!=L) {
Printf (" % d ", p - & gt; The data);
P=p - & gt; Next;
}
Printf (" % d ", p - & gt; The data);
}

NODE * delprev (NODE * p, int b) {

The NODE * L, * r * k;
L=p;

While (L - & gt; Next - & gt; The data!=b)
{r=L;
L=L - & gt; Next; }
K=L - & gt; Next;
R - & gt; Next=k;
Free (L);
Return (k);
}

Int main ()
{
int a;
The NODE * L, * p;

Printf (" new list \ n input values to end - 1: ");
P=creat ();
Shuchu (p);
Printf (" the value of the specified node p: ");
The scanf (" % d ", & amp; a);
L=delprev (p, a);
Shuchu (L);
}

For your reference ~

The original poster is circular linked list, but there is no special handling shuchu function, so it is infinite loop,

Have modified elsewhere, for your reference ~




Agghh thank
  • Related