# Include <iostream. h>
# Include <stdlib. h>
# Define list_init_size 100
# Define OK 1
# Define overflow-2
# Define error 0
Typedef int status;
Typedef int elemtype;
Typedef struct lnode {
Elemtype data;
Struct lnode * next;
} Lnode, * linklist;
Status initlist_l (linklist & L)
{
L = new lnode;
If (! L) Exit (overflow );
L-> next = NULL;
Return OK;
}
Void listcreat_l (linklist & L, int N)
{
Elemtype X;
Lnode * P, * q;
Q = L;
Cout <"input x (n) =" <Endl;
For (INT I = N; I> 0; I --)
{
P = new lnode;
If (! P) Exit (overflow );
Cin> X;
P-> DATA = X;
P-> next = NULL;
Q-> next = P;
Q = Q-> next;
}
}
Status listdelete_l (linklist & L, int I, elemtype & E)
{
Lnode * P, * q;
Int J;
P = L;
J = 0;
While (p-> next & J <i-1) {P = p-> next; + + J ;}
If (! P-> next | j> i-1)
Return Error;
Q = p-> next; P-> next = Q-> next;
E = Q-> data;
Delete Q;
Return OK;
}
Void findmin (linklist & L)
{
Elemtype result;
Int I = 1;
Int minnum = 1; // a variable with the minimum record position is set here, which is the key
Lnode * P;
P = L-> next;
Elemtype min;
If (! P) Exit (error );
Min = L-> next-> data;
While (P)
{
I ++;
If (p-> data <= min)
{
Min = p-> data;
Minnum = I;
}
P = p-> next;
}
Listdelete_l (L, minnum, result );
Cout <"the element you deleted is" <result <Endl;
}
Void vist_l (linklist L)
{
Lnode * P = L-> next;
While (P)
{
Cout <p-> data <"";
P = p-> next;
}
Cout <Endl;
}
Void main ()
{
Linklist L;
Initlist_l (L );
Listcreat_l (L, 5 );
Findmin (L );
Vist_l (L );
}