| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 595 人关注过本帖
标题:简单的链表建立与输出,我挂了
只看楼主 加入收藏
小草爱上兔
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-12-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
简单的链表建立与输出,我挂了
在结束建立的时候就自动关闭程序。。。。。。。。求大神看一下。。。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";
}

搜索更多相关主题的帖子: long next keyword include write 
2013-04-14 01:32
小草爱上兔
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-12-13
收藏
得分:0 
人的  还有  日期的我还没有弄。。。。。。。。暂时忽略吧

有你的冬天不会冷。。。。。。。。
2013-04-14 01:33
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:20 
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-04-14 23:30
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct Book
{
    long Isew;
    char name[20];
    char write[20];
    char print[20];
    char *keyword[5];
    int wordnum;
    struct  Book *next;
};
struct Date
{
    int year;
    int month;
    int day;
   struct Date *next;
};
struct Person
{
    char name[20];
    long tele;
    struct  Date dateb;
};


Book * creat()
{
   
   int i;
   Book *h,*q,*p;
//   h=NULL;
   h=new Book;
   h->next=NULL;
   p=new Book;
   p->next=NULL;
 //  q=p;
   q=h;
   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>>p->wordnum;
     cout<<"\nEnter the keyword:\n";
     for(i=0;i<p->wordnum;i++)
     {
         p->keyword[i]=new char(10);
         cin>>p->keyword[i];
     }
   /*   if(h==NULL)  h=p;
      else   q->next=p;
      q=p;  */
     p->next=NULL;
     q->next=p;
     q=q->next;
      p=new Book;
      cout<<"\n\t\tIsew:"; cin>>p->Isew;
    }
 //    q->next=NULL;e
   delete p;
     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->next;
if(p==NULL) cout<<"\t\t The List is NULL!"<<endl;
else
{
   do
   {
     cout<<"   Isew:"<<p->Isew<<endl;
     cout<<"   name:"<<p->name<<endl;
     cout<<"  write:"<<p->write<<endl;
     cout<<"  print:"<<p->print<<endl;
     cout<<"keyword:";
     for (int i=0; i<p->wordnum; ++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<<endl;
   cout<<"The Data of Book"<<endl;;
      
   print(book);

   cout<<endl<<"****************************************************************************"<<endl;
   cout<<"\t\t Continue(yes--anykey/not--'n')?"<<endl;
   ch=getch();destruct(book);
   if(ch=='n')  ch='n';
  }while(ch!='n');
  cout<<"\t\t End the program"<<endl;
}
2013-04-14 23:31
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
如果编译完提示有warning的话你就直接运行它,忽略warning。
2013-04-16 07:33
快速回复:简单的链表建立与输出,我挂了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039080 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved