首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

struct 链表有关问题()

2012-11-06 
struct 链表问题(求助)#includeiostreamusing namespace stdstruct student{__int64 numchar sexchar

struct 链表问题(求助)
#include<iostream>
using namespace std;
struct student  
{
__int64 num;
char sex;
char name[10];
char come_from[20];
struct student *next;//请问下这个跟student *next有何区别?;
};
struct student *head;
student *create()
{
struct student *ps; 
struct student *pend; 
ps=new student; 
scanf("%I64d",&ps->num);
cin>>ps->sex>>ps->name>>ps->come_from;
head=NULL;
pend=ps;
while(strcmp(ps->name,"null")!=0)// 这地方我想设置为有输入时执行,但是我不晓得这样写是否正确,求解
{
  if(head==NULL)
  {
  head=ps;
  }
  else
  {
  pend->next=ps;
  }
  pend=ps;
  ps=new student;
  scanf("%64d",&ps->num);
  cin>>ps->sex>>ps->name>>ps->come_from;
}
pend->next=NULL;
delete ps;
return head;
}
void show1(student *p)
{
while(head)
{
  printf("%64d",p->num);
  cout<<p->sex<<p->name<<p->come_from<<endl;
  head=head->next;
}
}
void main()
{
show1(create());
}
要求输入

20100862150 m zhang fuzou 



20100862178 f li shanghai 



20100862154 m wu sanming 



20100862155 f wang zhejian 



20100862170 f chen zhangzhou





并原样输出







本人初学小白,望大神能详解……谢谢


[解决办法]
1.没区别
2.while (ps->name)

热点排行