链表的操作

#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);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值