#include
#include
using namespace std;
typedef struct NODE
{
int number;
string name;
string sex;
int age;
struct NODE *pNext;
}*PNODE,node;
void travel_List(PNODE pHead)
{
PNODE p=pHead->pNext;
while(NULL!=p)
{
cout<<p->number<<" ";
cout<<p->name<<" ";
cout<<p->sex<<" ";
cout<<p->age<<" ";
p=p->pNext;
}
cout<<endl;
}
PNODE create_list(void)
{
PNODE pHead=new node;
PNODE pTail=pHead;
pTail->pNext=NULL;
for(int i=0; i<=1; i++)
{
int num;
string nm;
string sx;
int ag;
cin>>num;
getline(cin,nm);
getline(cin,sx);
cin>>ag;
PNODE pNEW=new node;
pNEW->number=num;
pNEW->name=nm;
pNEW->sex=sx;
pNEW->age=ag;
pTail->pNext=pNEW;
pNEW->pNext=NULL;
pTail=pNEW;
}
return pHead;
}
int main()
{
PNODE pHead=NULL;
pHead=create_list();
travel_List(pHead);
}
using namespace std;
typedef struct NODE
{
int number;
string name;
string sex;
int age;
struct NODE *pNext;
}*PNODE,node;
void travel_List(PNODE pHead)
{
PNODE p=pHead->pNext;
while(NULL!=p)
{
cout<<p->number<<" ";
cout<<p->name<<" ";
cout<<p->sex<<" ";
cout<<p->age<<" ";
p=p->pNext;
}
cout<<endl;
}
PNODE create_list(void)
{
PNODE pHead=new node;
PNODE pTail=pHead;
pTail->pNext=NULL;
for(int i=0; i<=1; i++)
{
int num;
string nm;
string sx;
int ag;
cout<<"num:";
cin>>num;
cin.get();
cout<<"Name:";
getline(cin,nm);
cout<<"Sex:";
getline(cin,sx);
cout<<"Age:";
cin>>ag;
PNODE pNEW=new node;
pNEW->number=num;
pNEW->name=nm;
pNEW->sex=sx;
pNEW->age=ag;
pTail->pNext=pNEW;
pNEW->pNext=NULL;
pTail=pNEW;
}
return pHead;
}
int main()
{
PNODE pHead=NULL;
pHead=create_list();
travel_List(pHead);
}
你試試這段代碼。