花圈材料生产厂家:数据结构的一段程序的调试

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/26 04:26:53
有哪位大哥帮着调个程序

#include <malloc.h>
#include <conio.h>
#define MaxLength 10
typedef struct LIST
{ char name[MaxLength];
int length;
struct LIST *next;
}LIST;
LIST a,l,b,c,*p,*head;

void print_list()
{do
{printf("%s\n",p->name);
p=p->next;
}while(p!=NULL);
}
insert_element(LIST l,,int i,char x)
{int k;
if(i<1||i>l.length+1)
return(0);
if(l.length>=MaxLength)
{printf("The sequenlist is overflow!");
return(-1);
}
for(k=l.length;k>=i-1;k--)
l.name[k+1]=l.name[k];
l.name[i-1]=x;
l.length++;
return(1);
}
delete_element(LIST l,int i)
{int k;
if(i>l.length||i<1)
{printf("The element you want to delete is not exist!");
return(0);
}
for(k=i;k<l.length;k++)

l.name[k-1]=l.name[k];
return(1);
}
LIST *insert_node(LIST *head,char x[MaxLength],int k)
{LIST *p,*pre,*s;
int j=1;
p=head;
pre=NULL;
while((p!=NULL)&&(j<k)) /*Find the pre-node of k. */
{ pre=p;
p=p->next;
j++;
}
if(j!=k)
{printf("The number of the node in the linklist is not reached k!");
return(0);
}
s=(LIST *)malloc(sizeof(LIST));
if(s==NULL)
printf("The memory is not enough!");
strcmp(s->name,x);
if(pre==NULL) /* When k=1. */
{s->next=head;
head=s;
}else
{s->next=pre->next;
pre->next=s;
}
return(head);
}
delete_node(LIST *head,int i)
{LIST *p,*q;
q=NULL;
p=head;
while(i--!=0&&p!=NULL)
{q=p;
p=p->next;
}
if(p==NULL)
{printf("The node not exist!");
return(0);
}else
{if(q==NULL)
head=head->next;
else q->next=p->next;
free(p);
}
}
main()
{int i,choice;
char x[MaxLength],element,listname;
LIST l;
clrscr();
strcpy(a.name,"Zhou"); a.length=4;
strcpy(b.name,"Xing"); b.length=4;
strcpy(c.name,"Chi"); c.length=3;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
printf("Welcome to use this programe!\nNow the exist list is:\n");
print_list();
printf("Please chose the function:\n1.Insert a element in a sequenlist.\n2.Delete a element in a sequenlist.\n3.Insert a node in the linklist.\n4.Delete a node in the link list.\n5.Quit the programe.\n");
scanf("%d",&choice);
switch(choice)
{case 5:{printf("Thanks to use!Good bye!");
break;}
case 1:{printf("Input the list name:");
scanf("%c",&listname);
printf("Input where the element you Insert:");
scanf("%i",&i);
printf("Input the element you want to Insert:");
scanf("%c",&element);
if(listname=='a') l=a;
if(listname=='b') l=b;
if(listname=='c') l=c;
insert_element(l,i,element);
print_list();
}
case 2:{printf("Input the list name:");
scanf("%c",&listname);
printf("Input where the element you Delete:");
scanf("%i",&i);
if(listname=='a') l=a;
if(listname=='b') l=b;
if(listname=='c') l=c;
delete_element(l,i);
print_list();
}
case 3:{printf("Input where the node you want to Insert:");
scanf("%d",&i);
printf("Input the node you want to Insert:");
scanf("%c",&x);
insert_node(head,x,i);
print_list();
}
case 4:{printf("Input where the node you want to Delete:");
scanf("%d",&i);
delete_node(head,i);
print_list();
}
}
}

正确的
就是
insert_element(LIST l,,int i,char x) //多了个,
{int k;
if(i<1||i>l.length+1)
return(0);
if(l.length>=MaxLength)
{printf("The sequenlist is overflow!");
return(-1);
}