主题:一个链表程序,请帮忙纠正一下错误,谢谢
大家好,蓝莓公主这厢有礼了,下面是我变得一个程序,已经有高人帮助盖过了,所以现在Show(),Setnull(),Insert()函数都没有问题,问题出现在delete(),get()函数中,而我又不知道如何改,希望大家能够帮帮忙,谢啦!
#include<iostream.h>
#include <stdio.h>
#include <malloc.h>
typedef char datatype;
typedef struct node
{datatype data;
struct node *next;
}linklist;
linklist *Setnull()
{linklist *head;
head=(linklist*)malloc(sizeof(linklist));
head->next=NULL;
/*head->data=0;/*?*/
cout<<"the list has bulit up"<<endl;
return(head);
}
void Show(linklist *head)
{
char ch;
linklist *p;
if(head==NULL)
{
cout<<"there isn't any progress!"<<endl;
return;
}
while(head!=NULL)
{
cout<<"the progress include:"<<head->data<<endl;
head=head->next;
}
}
void INSERT(linklist *head,char ch)
{
head->data=ch;
cout<<"the progress has insert it"<<endl;
}
void DELETEAFTER(linklist *head,linklist *p)
{linklist *r;
/*p=(linklist*)malloc(sizeof(linklist));*/
while(head->next!=p)
{head=head->next;}
p->next=head->next;
free(p);
cout<<"the progress has been deleted!"<<endl;
Show(head);
}
void GET (linklist *head,char ah)
{
linklist *p;
p=head->next;
while(p!=NULL)
if(p->data!=ah)
p=p->next;
else break;
cout<<"the progress has been finded";
cout<<" now we will delete it!"<<endl;
DELETEAFTER(head,p);
}
void name()
{
cout<<"wen"<<endl;
}
void main()
{
linklist *head1;
head1=Setnull();
cout<<"now please input the progress U want to insert!"<<endl;
char ch;
ch=getchar();
INSERT(head1,ch);
Show(head1);
/*name();
cout<<"I love you!"<<endl;*/
cout<<"please input the name you want to find!"<<endl;
char ah;
ah=getchar();
GET(head1,ah);
}
#include<iostream.h>
#include <stdio.h>
#include <malloc.h>
typedef char datatype;
typedef struct node
{datatype data;
struct node *next;
}linklist;
linklist *Setnull()
{linklist *head;
head=(linklist*)malloc(sizeof(linklist));
head->next=NULL;
/*head->data=0;/*?*/
cout<<"the list has bulit up"<<endl;
return(head);
}
void Show(linklist *head)
{
char ch;
linklist *p;
if(head==NULL)
{
cout<<"there isn't any progress!"<<endl;
return;
}
while(head!=NULL)
{
cout<<"the progress include:"<<head->data<<endl;
head=head->next;
}
}
void INSERT(linklist *head,char ch)
{
head->data=ch;
cout<<"the progress has insert it"<<endl;
}
void DELETEAFTER(linklist *head,linklist *p)
{linklist *r;
/*p=(linklist*)malloc(sizeof(linklist));*/
while(head->next!=p)
{head=head->next;}
p->next=head->next;
free(p);
cout<<"the progress has been deleted!"<<endl;
Show(head);
}
void GET (linklist *head,char ah)
{
linklist *p;
p=head->next;
while(p!=NULL)
if(p->data!=ah)
p=p->next;
else break;
cout<<"the progress has been finded";
cout<<" now we will delete it!"<<endl;
DELETEAFTER(head,p);
}
void name()
{
cout<<"wen"<<endl;
}
void main()
{
linklist *head1;
head1=Setnull();
cout<<"now please input the progress U want to insert!"<<endl;
char ch;
ch=getchar();
INSERT(head1,ch);
Show(head1);
/*name();
cout<<"I love you!"<<endl;*/
cout<<"please input the name you want to find!"<<endl;
char ah;
ah=getchar();
GET(head1,ah);
}