#include "stdlib.h" #include "stdio.h" #include "string.h" typedef struct NODE {int data;
struct Node *next;
}slist;
Slist *creat_slist () {//1 Create a header node and initialize slist *phead = NULL by the method of tail interpolation;
Slist *pcur = NULL;
Slist *pm = NULL;
int data = 0;
Pcur = Phead = (slist *) malloc (sizeof (slist));
Phead->data = 0;
Phead->next = NULL;
2 loops Create nodes, values from the Node data field input from the keyboard,//1 as the input end sign printf ("\nplease enter the data of node ( -1:quit)");
scanf ("%d", &data);
while (data!=-1) {PM = (slist*) malloc (sizeof (slist));
Pm->data = data;
Pm->next = NULL;
Pcur->next = PM;
Pcur = PM;
printf ("\nplease enter the data of node ( -1:quit)");
scanf ("%d", &data);
return phead;
int Slist_print (slist *phead) {slist* pcur = NULL;
if (!phead) {return-1;
} pcur = phead->next;
while (pcur) {printf ("%d\n", pcur->data);
Pcur = pcur->next;
return 1;
Insert y int slist_nodeinsert (slist *phead, int x, int y) {slist* PM = NULL before the node value is x; slist* Pcur = NULL;
slist* pLast = NULL;
if (!phead) {return-1;
} pLast = Phead;
Pcur = phead->next;
PM = (slist*) malloc (sizeof (slist));
Pm->data = y;
Pm->next = NULL;
while (pcur) {if (Pcur->data = = x) {break;
} pLast = Pcur;
Pcur = pcur->next;
} pm->next = Pcur;
Plast->next = PM;
return 1;
///delete the node as Y of the linked list node int slist_nodedel (slist *phead, int y) {slist* pcur = NULL;
slist* pLast = NULL;
if (!phead) {return-1;
} pLast = Phead;
Pcur = phead->next;
while (pcur) {if (Pcur->data = = y) {break;
} pLast = Pcur;
Pcur = pcur->next;
} if (!pcur) {return-1;
} Plast->next = pcur->next;
Free (pcur);
return 1;
int slist_destory (slist *phead) {slist* pnext = NULL;
slist* pcur = NULL;
if (!phead) {return-1;
} pcur = Phead;
Pnext = pcur->next;
while (1) {free (pcur);
Pcur = Pnext;
if (!pcur) {break;
} Pnext = pnext->next;
return 1; int MaiN () {slist* phead = creat_slist ();
if (!phead) {return-1;
} slist_print (Phead);
Slist_nodeinsert (Phead, 20, 19);
Slist_print (Phead);
Slist_nodedel (Phead, 19);
Slist_print (Phead);
Slist_destory (Phead);
return 0; }