该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
typedef struct Node {
int data;
struct Node *next;}Node,*Sq;
void main()
{
Sq L,p,s,q; int a,b,i,j=0,k,h=0,e,m;
//************创建空链表*********//
L=(Sq)malloc(sizeof(Node));
if(!L) printf("OVERFLOW");
L->next=NULL;
//***********输入数据*************//
scanf("%d",&a);
for(b=a;b>0;--b){
p=(Sq)malloc(sizeof(Node));
scanf("%d",&p->data);
p->next=L->next;L->next=p;}
//*****************输入要插入数据*************//
printf("please enter the insertnum :\n");
scanf("%d" ,&e);
printf("Its location:");
scanf("%d",&i);
p=L;
while(p&&j
{p=p->next;++j;}
if (!p||j>i-1) printf("error");
s=(Sq)malloc(sizeof(Node));
s->data=e; s->next=p->next;p->next=s;
p=L->next;
while(p!=NULL){
printf("%5d",p->data); p=p->next; }
printf("\n");
//***************删除数据*************//
printf("Please input the loc :\n") ;
scanf("%d",&k);
p=L;
while(p->next&&h
{p=p->next;++h;}
if (!(p->next)||h>k-1) printf("error");
q=p->next;p->next=q->next;m=q->data;free(q);
printf("the num you delete is %d\n",m);
p=L->next;
while(p!=NULL)
{printf("%5d",p->data);p=p->next;}
}