#include
Typedef struct LNode
{
int data;
Struct LNode * next;
} LNode * LinkList;
Int InitList (LinkList & amp; L)
{
L=(LinkList) malloc (sizeof (LNode));
If (L==NULL)
return false;
L-> Next=NULL;
return true;
}
Int chucun (LinkList L, int a [], int I)
{
LinkList s;
While (i<5)
{
S=(LinkList) malloc (sizeof (LNode));
S - & gt; Next=NULL;
L-> data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=L - & gt; Next;
L-> Next=s; S - & gt; data=https://bbs.csdn.net/topics/L-> data;
i++;
}
}
LinkList charu (int LNode * L, c)
{
LinkList p; Int j=0, I=2;
P=L;
While (j{
P=p - & gt; Next; + + j;
}
LinkList s;
S=(LinkList) malloc (sizeof (LNode));
S - & gt; data=https://bbs.csdn.net/topics/c; S -> next=p -> next;
P - & gt; Next=s;
The return of L - & gt; Next;
}
Int shanchu (LinkList L, int I) {
LinkList p, s;
Int j=0;
P=L;
while(! (p - & gt; Next) & amp; & jP=p - & gt; Next, j++; }
S=p - & gt; Next;
P - & gt; Next=s - & gt; Next;
Free (s);
S=NULL;
}
Void printlist (LinkList L) {
LinkList temp=L;
Printf (" list of values for \ n ");
While (temp) {
Temp=temp - & gt; Next;
Printf (" % d \ n ", temp - & gt; The data); }
}
Int main () {
LinkList L;
InitList (L);
11,22,33,44,66 int a []={};
int i=0;
Int c=55;
Chucun (L, a, I);
Printf (" print store list \ n ");
Printlist (L);
Charu (L, c);
Printf (" print insert list \ n ");
Printlist (L);
Shanchu (L, 5);
Printf (" print after delete list \ n ");
Printlist (L);
}
CodePudding user response:
# include
#include
Typedef struct LNode
{
int data;
Struct LNode * next;
} LNode * LinkList;
Int InitList (LinkList & amp; L)
{
L=(LinkList) malloc (sizeof (LNode));
If (L==NULL)
return false;
L-> Next=NULL;
return true;
}
//store
//int chucun (LinkList L, int a [], int I)
Int chucun (LinkList L, int a [], int len)
{
int i=0;
LinkList s;
While (I & lt; Len)
{
S=(LinkList) malloc (sizeof (LNode));
if (! S)
return -1;
S - & gt; Data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=L - & gt; Next;
L-> Next=s;
/* s - & gt; Next=NULL;
L-> data=https://bbs.csdn.net/topics/a [I];
S - & gt; Next=L - & gt; Next;
L-> Next=s; S - & gt; data=https://bbs.csdn.net/topics/L-> data;
*/
i++;
}
return 0;
}
LinkList charu (LNode * L, int pos, int c)
{
LinkList p;
Int j=0, I=2;
P=L;
While (j & lt; Pos - 1 & amp; & P - & gt; Next)
{
P=p - & gt; Next; + + j;
}
LinkList s;
S=(LinkList) malloc (sizeof (LNode));
S - & gt; data=https://bbs.csdn.net/topics/c;
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
//return L - & gt; Next;
return L;
}
Int shanchu (LinkList L, int I)
{
LinkList p, s;
Int j=0;
P=L;
//while (! (p - & gt; Next) & amp; & jWhile ((p - & gt; Next) & amp; & jP=p - & gt; Next, j++;
}
If (p - & gt; Next==NULL)
return -1;
S=p - & gt; Next;
P - & gt; Next=s - & gt; Next;
Free (s);
S=NULL;
return 0;
}
Void printlist (LinkList L)
{
LinkList temp=L - & gt; Next;
Printf (" list of values for \ n ");
While (temp) {
Printf (" % d \ n ", temp - & gt; The data);
Temp=temp - & gt; Next;
}
}
//int main ()
Int main (void)
{
LinkList L;
InitList (L);
11,22,33,44,66 int a []={};
int i=0;
Int c=55;
Chucun (L, a, sizeof (a)/sizeof (a [0]));
Printf (" print store list \ n ");
Printlist (L);
Charu (L, 2, c);
Printf (" print insert list \ n ");
Printlist (L);
Shanchu (L, 5);
Printf (" print after delete list \ n ");
Printlist (L);
return 0;
}
For your reference ~
CodePudding user response:
The