自己学数据结构,单链表 c 实现一直出错,求大神修改
#include <stdio.h>#include <malloc.h>
#define ERROR 0;
#define OK 1;
typedef struct num{
int data;
struct num *next;
}*linklist;
struct num *create()
{
struct num *head,*current,*next;
int copy;
char judge;
printf("please input number:\n");
scanf("%d",©);
getchar();
head=(struct num*)malloc(sizeof(struct num));
head->data=copy;
current=head;
printf("是否继续输入:");
scanf("%c",&judge);
while(judge!='N')
{
printf("please input num:\n");
scanf("%d",©);
getchar();
next=(struct num*)malloc(sizeof(struct num));
next->data=copy;
current->next=next;
current=next;
printf("是否继续输入:");
scanf("%c",&judge);
}
current->next=NULL;
return head;
}
void list(struct num *p)
{
while(1)
{
printf("%s\n",p->data);
if(p->next!=NULL)
p=p->next;
else
break;
}
}
Insert(linklist p,int i,int e)
{
linklist q,s;
int j=1;
while(q&&j<i-1)
{
q=q->next;
++j;
}
if(!q||j>i)
return ERROR;
s=(struct num*)malloc(sizeof (struct num));
s->data=e;
s->next=q->next;
q->next=s;
return OK;
}
int main()
{
struct num *p;
p=create();
list (p);
int a,e;
printf("请输入要插入数字的位置:\n");
scanf("%d",&a);
printf("请输入数字:\n");
scanf("%d",&e);
Insert(p,a,e) ;
list(p) ;
return 0;
}
问题是我不再想输入数字时,输入了N,程序就停止进行了 T U T
求大神指点 万分感谢
[ 本帖最后由 lamsosad 于 2014-10-15 17:11 编辑 ]