链表的操作
2013-09-15 21:59
274 查看
#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); } }
相关文章推荐
- 数据结构--单链表基本操作
- c++链表的创建与操作;
- 链表常见操作java实现一:链表初始化,求链表长度
- 链表的一些基本操作
- 链表的相关操作函数
- 数据结构-单向链表相关操作算法
- 广州海格2016年笔试题,关于链表的操作
- C语言链表各种操作
- 链表的操作
- 数据结构之单链表、双链表的基本操作
- C语言实现单链表相关操作
- 链表的基本操作
- 链表操作
- 【C语言】单链表的所有操作的实现(包括PopBack、PushBack、PopFront、PushFront、Insert)
- Redis-链表类型操作
- C语言----链表的各项操作总结----单项循环链表
- C++中单链表的基本操作:判空、增、删、显示
- C++中链表操作实例分析
- 数据结构作业多链表操作之寻找公共节点。
- Java中单链表的部分操作总结