单链表的问题急

来源:百度知道 编辑:UC知道 时间:2024/06/09 14:07:34
我的程序如下
主要看主函数部分
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#define NULL 0
typedef struct node
{ char str[16];
int data;
struct node *next;
} dial;
#define LEN sizeof(dial)
dial *creat(int n) /* creat the sets */
{ dial *r,*s;
dial *head;
int i;
head=NULL;
r=NULL;
i=1;
while(i<=n)
{ s=(dial*)malloc(LEN);
gets(s->str);
if(head==NULL) head=s;
else r->next=s;
r=s;
i++;
}
if(r!=NULL) r->next=NULL;
return head;
}
void convert(char *a) /* convert the dial to standard form */
{ char temp[16];
int i,j,k;
a=temp;
i=0;
while(a[i]!='\0')
{ if(!isalnum(a[i]))
{ for(j=i;j<14;j++)
a[j]=a[j+1];
}
i++;

}
for(j=6;j>=3;j--)
a[j+1]=a

虽然不知道你的程序想说什么,但是死循环是因为delete,
delete(dial *p,dial *head)
{ dial *temp;
temp=head;
while(temp->next!=p)
temp=temp->next;
// p->next=temp->next;//这一句改在下面
free(p);

}

改为temp->next=p->next;

还有,下次有发这种程序上来,麻烦写上注释,不然看得好头痛啊。。。。

我试图帮你改下发现你的写法毫无章法和格式,注释也没有叫人怎么看啊,实在看不下去了。顺便说下你的创建函数有问题。

程序写的有点乱,
最明显的一个错误是switch语句后面分支没有加break,而且按你的写法
totable函数没有任何作用.