分享
 
 
 

链表 List.h

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

///////////////////////////

// //

// 链表 List.h //

// //

//////////////////////////

#include"list.h"

#include<iostream.h>

#include<stdlib.h>

template<class type>

void initlist(type &tmp)

{

list<type> List;

int n;

while(true)

{

cout<<"请选择你要对链表进行的操作 "<<endl

<<"1) 在末尾插入数据"<<endl

<<"2) 在任意处插入数据"<<endl

<<"3) 删除数据项"<<endl

<<"4) 删除整个链表"<<endl

<<"5) 打印链表"<<endl

<<"6) 查找数据项"<<endl

<<"7) 退出"<<endl;

cout<<">\ ";

cin>>n;

while(n<1||n>7)

{

cout<<"输入有误,请从新输入!"<<endl;

cout<<">\ ";

cin>>n;

}

switch(n)

{

case 1: list_insertend(List);break;

case 2: list_insert(List);break;

case 3: list_delnode(List);break;

case 4: list_makeempty(List);break;

case 5: list_print(List);break;

case 6: list_find(List);break;

case 7: return ;break;

}

}

}

void LIST()

{

int n;

cout<<"请选择你要构造的链表的数据类型 1)整型,2)字符型,3)浮点型"<<endl;

cout<<">\ ";

cin>>n;

while(n<1||n>3)

{

cout<<"输入有误,请从新输入!"<<endl;

cout<<">\ ";

cin>>n;

}

char t_c='c';

int t_i=12;

double t_f=23.3;

switch(n)

{

case 1:initlist(t_i);break;

case 2:initlist(t_c);break;

case 3:initlist(t_f);break;

}

}

template<class type>

void list_insertend(list<type> &L)

{

type t;

cout<<"请输入插入数据: >\";

cin>>t;

L.insertend(t);

}

template<class type>

void list_find(list<type> &L)

{

type T;

cout<<"请输入你要查找的数据项:>\ ";

cin>>T;

int i;

if(!(i=L.find(T)))

cout<<"你要查找的数据项不存在!"<<endl;

else

cout<<"你要查找的数据项在第"<<i<<"个位置"<<endl;

}

template<class type>

void list_insert(list<type> &L)

{

type t;

cout<<"请输入插入数据: >\";

cin>>t;

int n;

cout<<"请输入插入位置: >\";

cin>>n;

if(L.insert(t,n))

cout<<"插入成功! 在"<<n<<"位置 插入"<<t<<endl;

else

cout<<"插入失败! 插入位置不正确!"<<endl;

}

template<class type>

void list_delnode(list<type>& L)

{

int i;

cout<<"请输入要删除数据项的位置: >\";

cin>>i;

while(i<1||i>L.getlen())

{

cout<<"输入有误,可能大与链表长度,请从新输入!"<<endl;

cout<<">\ ";

cin>>i;

}

L.delnode(i);

}

template<class type>

void list_makeempty(list<type> &L)

{

L.makeempty();

}

template<class type>

void list_print(list<type> &L)

{

if(!L.print())

cout<<"链表为空!"<<endl;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有