链表 List.h

///
//    //
//   链表     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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值