#include#include #include typedef int ElemType;typedef struct Node{ ElemType data; struct Node *next; }Node,*LinkedList;LinkedList Creatlist(LinkedList head){ int i,d; LinkedList p,q; p = head; printf("请输入链表元素,输入为404时停止输入 :"); while(1) { scanf("%d",&d); if(d!=404) { q = (LinkedList)malloc(sizeof(Node)); q->data = d; q->next = NULL; p->next = q; p = q;} else return false; } return head;}void PutList(LinkedList head,LinkedList p){ p = head->next; while(p){ printf("%d",p->data); p=p->next; }}void InsertList(LinkedList head){ if(!head){ printf("链表不存在"); return ; } int c = 0; LinkedList p = head; while(p!=NULL){ c++; if(c==5){ LinkedList temp = (Node*)malloc(sizeof(Node)); temp->data =999; temp->next = p->next; p->next = temp; break; } p= p->next; } }//删除第五个元素 void Del(LinkedList head){ LinkedList p; int c=0; if(!head){ printf("链表不存在"); return ; } p = head; while(p){ c++; if(c==5){ p->next = p->next->next; } p= p->next; } }//删除指定区域的元素void DelList(LinkedList head,int mink,int maxk){ LinkedList p,q,temp; if(!head){ printf("链表不存在"); return; } temp = head; p = head; while(p->next){ if(p->next->data>=mink&&p->next->data<=maxk){ q = p->next; p->next = q->next; free(q); } else p = p->next; } } int main(){ LinkedList head,p; head = (LinkedList)malloc(sizeof(Node)); head->next = NULL; int n,i,mink,maxk; Creatlist(head); printf("输入相应编号,执行操作\n1.遍历单链表\n2.在单链表中插入元素\n3.删除单链表中的元素\n4.删除指定区域的元素;"); scanf("%d",&i); switch(i){ case 1: PutList(head,p); break; case 2: InsertList(head); p = head->next; while(p){ printf("%d",p->data); p=p->next; } break; case 3: Del(head); p = head->next; while(p){ printf("%d",p->data); p=p->next; } break; case 4: printf("请输入删除的范围"); scanf("%d %d",&mink,&maxk); DelList(head,mink,maxk); //printf("1===") ; p= head->next; while(p){ printf("%d",p->data); p=p->next; } break; } return 0; }