Home > other >  Why the program terminates, singly linked lists have error range for bosses to help
Why the program terminates, singly linked lists have error range for bosses to help

Time:09-27


Code:
//Init initialization initialization list
//Build to create a new list
//Insert input location input data to add
//Delete (Linklist * L, int I) I is to remove the location of the
//Updat (Linklist * L, int I Type elem) I was location data elem is to change
//long length o list
//Print to Print list
//Search (Linklist * L, int elem) to find the location of the chain is the same as the input data in the table
#include
#include
Typedef int Type.
Typedef int the Status;
Typedef struct node {
Type the date;//data domain
Struct node * next;//pointer field
} Lnode * Linklist;
The Status Init (Linklist * L)
{
Lnode * H=(Linklist) malloc (sizeof (Lnode));
H - & gt; Next=NULL;
Printf (" initial success ");
return 1;
}
The Status Build (Linklist * L)//stern interpolation
{
int n;
Printf (" you want to create the list length: \ n ");
The scanf (" % d ", & amp; N);
Linklist p, temp.
Temp=(* L);
While (n> 0)
{
P=(Linklist) malloc (sizeof (Lnode));
The scanf (" % d ", & amp; p-> The date);
p-> Next=NULL;
Temp - & gt; Next=p;
Temp=p;
N -;
}
Printf (" list to create success ");
return 1;
}
Void length (Linklist L)
{
int sum;
While (L - & gt; Next)
{
Sum++;
L=L - & gt; next;
}
printf("%d",sum);
}
The Status Insert (Linklist * L, int I, Type elem)
{
Linklist p;
P=(* L);
Int j=0;
While (p& & i{
P=p - & gt; next;
j++;
}
If (p& & I==j)
{
Lnode * H=(Linklist) malloc (sizeof (Lnode));
H - & gt; The date=elem;
H - & gt; Next=p - & gt; next;
p-> Next=H - & gt; next;
Return 0;
}
}
The Status the Delete (Linklist * L, int I)
{
Linklist p=(* L);
Int j=0;
While (p& & i{
P=p - & gt; next;
j++;
}
If (p& & I==j)
{
Linklist H;
H=p - & gt; next;
p-> Next=H - & gt; next;
Free (H);
}
return 0;
}
The Status Update (Linklist * L, int I Type elem)
{
Int j=1;
While (L& & J{
(* L)=(* L) - & gt; next;
j++;
}
If (L& & J==I)
{
(* L) - & gt; The date=elem;
}
return 0;
}
The Status Search (Linklist L, int I)
{
Int j=1;
While (L& & J{
L=L - & gt; next;
j++;
}
If (I==j)
{
Printf (" % d, L - & gt; The date);
}
return 0;
}
The Status Print (Linklist L)
{
While (L)
{
Printf (" % d, L - & gt; The date);
L=L - & gt; next;
}
return 0;
}

Int main (void)
{
Linklist a;
Init (& amp; A);
Build (& amp; A);
Insert (& amp; A, 2, 3);
Print (a);
Delete (& amp; A, 2);
The Update (& amp; A, 2, 4);
Print (a);
To Search (a, 3);
return 0;
}
  • Related