简单的链表建立与输出,我挂了
在结束建立的时候就自动关闭程序。。。。。。。。求大神看一下。。。VC6上运行#include<iostream.h>
#include<conio.h>
struct Book
{
long Isew;
char name[20];
char write[20];
char print[20];
char *keyword[5];
Book *next;
};
struct Date
{
int year;
int month;
int day;
Date *next;
};
struct Person
{
char name[20];
long tele;
Date dateb;
};
Book *creat()
{
int i,m;
Book *h,*q,*p;
h=NULL;
p=new Book;
q=p;
cout<<"\n\t\tIsew:";
cin>>p->Isew;
while(p->Isew!=0)
{
cout<<"\n\t\t name:"; cin>> p->name;
cout<<"\n\t\twrite:"; cin>> p->write;
cout<<"\n\t\tprint:"; cin>> p->print;
for(i=0;i<5;i++)
{
p->keyword[i]=new char(10);
p->keyword[i]=0;
}
cout<<"\nHow many keyword in the book?";
cin>>m;
cout<<"\nEnter the keyword:\n";
for(i=0;i<m;i++)
{
p->keyword[i]=new char(10);
cin>>p->keyword[i];
}
if(h==NULL) h=p;
else q->next=p;
q=p;
p=new Book;
cout<<"\n\t\tIsew:"; cin>>p->Isew;
}
q->next=NULL;
return h;
}
void destruct(Book* h)
{ Book *p;
p=h;
while(h!=NULL)
{ h=p->next;
delete p;
p=h;
}
}
void print(Book *h)
{
Book *p;
/*for(int i=0;i<5;i++)
{
p->keyword[i]=p1[i];
}*/
p=h;
if(h==NULL) cout<<"\n\t\t The List is NULL!\n";
else
{
do
{
cout<<"\n Isew:"<<p->Isew;
cout<<"\n name:"<<p->name;
cout<<"\n write:"<<p->write;
cout<<"\n print:"<<p->print;
cout<<"\nkeyword:\n";
for (int i = 0; i < 5; ++i)
{
cout <<p->keyword[i]<<"\t";
}
p=p->next;
}while(p!=NULL);
}
}
void main()
{
Book *book;
int N;
char ch;
do
{
// clrscr();
cout<<"Creat the Data about Book\n";
book=creat();
// clrscr();
cout<<"\nThe Data of Book\n";
print(book);
cout<<"\n\n\****************************************************************************\n\n";
cout<<"\n\t\t Continue(yes--anykey/not--'n')?";
ch=getch();destruct(book);
if(ch=='n') ch='n';
}while(ch!='n');
cout<<"\n\t\t End the program\n";
}