# include
#include
Struct Node;
Typedef struct Node * PNode;
Struct Node {
Int the info;
PNode link;
};
Typedef struct Node * LinkList;
Typedef LinkList * PLinkList;
Void createlink (PLinkList pclist, int n)//build singly linked lists and initialise
{
PNode p, q;
int i;
P=(PNode) malloc (sizeof (struct Node));
* pclist=p;
P - & gt; Info=1;
Q=(PNode) malloc (sizeof (struct Node));
Q - & gt; Info=2;
P - & gt; The link=q;
P=q;
For (I=3; I & lt;=n; I++)
{
Q=(PNode) malloc (sizeof (struct Node));
P - & gt; The link=q;
Q - & gt; Info=I;
P=q;
}
P - & gt; The link=NULL;
return;
}
Void deletei_link (PLinkList pclist, int num)
{
PNode p, pre=NULL;
P=* pclist;
int count=1;
While (the count! Num=& amp; & P - & gt; The link!=NULL)
{
The pre=p;
P=p - & gt; The link;
count++;
}
The pre - & gt; The link=p - & gt; The link;
Free (p);
return;
}
Int main ()
{
int n; Int num.
Scanf_s (" % d ", & amp; N);
PLinkList pclist=NULL;
Createlink (pclist, n);
Scanf_s (" % d ", & amp; Num);
Deletei_link (pclist, num);
PNode w;
W=* pclist;
While (w!=NULL)
{
Printf (" % d ", w - & gt; Info);
W=w - & gt; The link;
}
return 0;
}
CodePudding user response:
Solved the space inside the main function does not cause palist classification, there are some other detailsCodePudding user response:
# include
#include
Struct Node;
Typedef struct Node * PNode;
Struct Node {
Int the info;
PNode link;
};
Typedef struct Node * LinkList;
Typedef LinkList * PLinkList;
Void createlink (PLinkList pclist, int n)//build singly linked lists and initialise
{
PNode p, q;
int i;
P=(PNode) malloc (sizeof (struct Node));
if (! P)
exit(0);
* pclist=p;
P - & gt; Info=1;
Q=(PNode) malloc (sizeof (struct Node));
if (! Q)
exit(0);
Q - & gt; Info=2;
P - & gt; The link=q;
P=q;
For (I=3; I & lt;=n; I++)
{
Q=(PNode) malloc (sizeof (struct Node));
P - & gt; The link=q;
Q - & gt; Info=I;
P=q;
}
P - & gt; The link=NULL;
return;
}
Void deletei_link (PLinkList pclist, int num)
{
PNode p, pre=NULL;
P=* pclist;
int count=1;
The pre=* pclist;
While (the count! Num=& amp; & P - & gt; The link!=NULL)
{
The pre=p;
P=p - & gt; The link;
count++;
}
If (count! Num)={
Printf (" Can 't find it! \n");
return;
}
If (p==* pclist) {
* pclist=(* pclist) - & gt; The link;
Free (p);
return;
}
The pre - & gt; The link=p - & gt; The link;
Free (p);
return;
}
Int main ()
{
int n; Int num.
Scanf_s (" % d ", & amp; N);
//the scanf (" % d ", & amp; N);
LinkList pclist=NULL;
Createlink (& amp; Pclist, n);
Scanf_s (" % d ", & amp; Num);
//the scanf (" % d ", & amp; Num);
Deletei_link (& amp; Pclist, num);
PNode w;
W=pclist;
While (w!=NULL)
{
Printf (" % d ", w - & gt; Info);
W=w - & gt; The link;
}
}
For your reference ~
The building code does not consider to remove the first node and the count!=num, which are not eligible to ~ to be deleted