求大神幫我看看這個題的插入演算法中哪裡錯了??(帶頭節點的單鏈表)
#include<stdio.h> #include<stdlib.h> typedef int elementype; #define OK 1 #define EORR 0 typedef struct node { elementype element; struct node *link; }node; typedef struct { struct node head;/定義頭指標/ int n; }headerlist; elementype init(headerlist p)/對帶頭結點的連結串列進行初始化/ { p->head=(node)malloc(sizeof(node)); if(!p->head) return EORR; p->head->link=NULL; p->n=0; return OK; } struct headerlist
elementype output(headerlist *p ) { node *s; s=p->head->link; int i; if(!p) return EORR; for(i=0;in;i++) {
printf("%d",s->element);
s=s->link;
}
return OK;
}
void main() { headerlist p,q,s; node w; int x,chioce,i,j,t; char answer; init(&p); printf(“您輸入的數字個數為:”); scanf("%d",&x); q=input(&p,x); do{ printf("*********************\n"); printf(“1.查詢 2.插入 3.刪除\n”); printf("************************\n"); printf(“您的選擇是:”); scanf("%d",&chioce); if(chioce1) { printf(“請輸入您要查詢的元素位置:”); scanf("%d",&i); printf(“您查詢的元素為%d”,find(q,i)); } if(chioce2) {
printf("請輸入您要插入的位置:");
scanf("%d",&i);
printf("請輸入您要插入的元素:");
scanf("%d",&j);
insert(q,i,j);
output(q);
}
if(chioce==3)
{
printf("請輸入您要刪除元素的位置:");
scanf("%d",&t);
Delete(q,t);
output(q);
}
printf("\n");
printf("您是否想再試一次?(y/n)");
getchar();
answer=getchar();
}while(answer==‘y’||answer==‘Y’); }