#include "iostream"
#include "string"
#include "windows.h"
using namespace std;
typedef class stuff
{
public:
int number;
string name;
class stuff *Next;
}Node;//,*LinkTable;
Node *CreateLink();
void OutPut(Node *Head);
int main()
{
Node *Head; //整个链表的头
Head = CreateLink();
OutPut(Head);
system("pause");
return 0;
}
Node *CreateLink()
{
int num;//保存输入的编号
string na;//保存输入的姓名
Node *head, *curr, *tail;
head = (Node *)malloc(sizeof(Node));//创建头节点
tail = head;
cout<<"please input the number:"<<endl;
cin>>num;
cout<<"please input the name:"<<endl;
cin>>na;
//创建新节点来保存输入的数据
while(10 != num)//&&(NULL != na))
{
curr = (Node *)malloc(sizeof(Node));
curr->number = num;
// curr->name = na;
tail->Next = curr;
tail = curr;
cout<<"please input the number:"<<endl;
cin>>num;
cout<<"please input the name:"<<endl;
cin>>na;
}
tail->Next = NULL;
return head;
}
void OutPut(Node *Head)
{
Node *p;
p = Head->Next;
if('\0' == p)
cout<<"Linktable is NULL!"<<endl;
else
{
do
{
cout<<p->number<<endl;
cout<<p->name<<endl;
p = p->Next;
}while(NULL != p);
}
}
链表的操作
最新推荐文章于 2023-01-24 16:48:30 发布