# Include <unistd. h>
# Include <stdlib. h>
# Include <stdio. h>
Typedef struct lnode
{
Int data;
Struct lnode * next;
} * Lnode;
// Init the single linked list
Void init_l (struct lnode * P)
{
Int N;
Int I = 0;
Lnode Q;
Lnode linklist;
// P = (lnode) malloc (sizeof (lnode ));
If (P = NULL)
{
Puts ("error! ");
Exit (0 );
}
Linklist = P;
While (P)
{
// I ++;
Scanf ("% d", & N );
If (n =-1)
Break;
Q = (lnode) malloc (sizeof (lnode ));
P-> DATA = N;
P-> next = Q;
P = Q;
I ++;
}
Q-> next = NULL;
For (I; I> 0; I --)
{
Printf ("/n % d/N", linklist-> data );
Linklist = linklist-> next;
}
}
// Insert the single linked list
Insert_l (struct lnode * P, int I, int N)
{
Int length = 0;
Int J = 1;
Struct lnode * linklist;
Lnode P1;
Lnode Q;
Linklist = P;
P1 = P;
While (p-> next! = NULL)
{
P = p-> next;
Length ++;
}
Printf ("Length: % d/N", length );
If (length <I) | (I <1 ))
Puts ("insert postion is error ");
Q = (lnode) malloc (sizeof (lnode ));
If (! Q)
{
Puts ("malloc errored! ");
Exit (0 );
}
While (P1-> next! = NULL) & (j <I-1 ))
{
P1 = p1-> next;
J ++;
}
If (P1-> next) = NULL | (j> I ))
{
Puts ("insert error! ");
Exit (0 );
}
Q-> DATA = N;
Q-> next = p1-> next;
P1-> next = Q;
While (linklist-> next! = NULL)
{
Printf ("% d/N", linklist-> data );
Linklist = linklist-> next;
}
}
// Delete from linklist
Delete_l (struct lnode * P, int I)
{
Lnode q = P;
Lnode Q1 = P;
Int J = 0;
/*
While (p-> next! = NULL)
{
Printf ("% d/N", p-> data );
P = p-> next;
}
Exit (0 );
*/
While (P-> next! = NULL) & (j <I-1 ))
{
Q1 = P;
P = p-> next;
J ++;
}
If (P-> next = NULL) | (j> I ))
{
Puts ("delete error! ");
Exit (0 );
}
Q1-> next = p-> next;
While (Q-> next! = NULL)
{
Printf ("% d/N", Q-> data );
Q = Q-> next;
}
}
Int main (INT argc, char ** argv)
{
Struct lnode * ll;
Int I;
Int N;
LL = (struct lnode *) malloc (sizeof (struct lnode ));
Init_l (LL );
Puts ("Please input the location and value of insert :");
Scanf ("% d", & I, & N );
Insert_l (LL, I, n );
Puts ("Please input the location of delete :");
Scanf ("% d", & I );
Delete_l (LL, I );
Return 0;
}