设为首页 加入收藏

TOP

线性表链式存储C++实现(三)
2014-04-06 17:34:50 来源: 作者: 【 】 浏览:265
Tags:线性 链式 存储 实现

 

  head.next = 0;

  pr = & head;

  return true;

  }

  //返回第一个数据节点迭代器,用于调用者遍历之用

  Iter begin()

  {

  return Iter(head.next);

  }

  //返回最后一个数据节点迭代器,用于调用者遍历之用

  Iter end()

  {

  return Iter(pr->next);

  }

  ~LsList(void)

  {

  }

  private :

  LNode head;//头节点

  LNode * pr;//指向表尾的指针

  size_t size;//元素个数

  };

  源。cpp

  #include<IOSTREAM>

  #include<LIST>

  #include<VECTOR>

  #include"LsList.h"

  using namespace std;

  int main()

  {

  LsList<INT> li;//建立一个空的线性表

  cout《LI.GETSIZE()《ENDL; LsList<int a ="{1,2,3};" int> mlist(a,3);//用数组初始化一个线性表

  cout《"数组初始化方式!"《ENDL;

  LsList<int cout《?list的元素个数为: 《mlist.GetSize()《endl;

  cout《endl; ;

  cout《mlist 《? cout《mlist 《? cout《mlist[0]《?> la;

  la = mlist ;//使用赋值操作符函数

  LsList<INT> lb(la) ;//使用复制构造函数初始化

  cout《"赋值操作符函数"《ENDL;

  { LsList<int cout《endl;

   ; cout《?迭代器高效遍历: 《endl;

  } cout《mlist[i]《? i="0;

  i<(int)mlist.GetSize();

  i++)" for(int cout《?在表首添加元素4,在表尾添加元素-1 《endl;

  向表尾段添加元素 mlist.push_front(-1);

  向表首段添加元素 mlist.push_back(4);

  cout《mlist.back()《endl;

  cout《?获取线性表的最后一个元素:

   《endl;

  获取线性表的首位元素 cout《mlist.front()

  《endl;

  cout《?获取线性表的第一个元素: 《endl;

  cout《lb 《? cout《lb 《?

  cout《lb[0]《? cout《?复制构造函数初始化?《endl;

  cout《la 《? cout《la 《? cout《la[0]《?>::Iter it = mlist.begin();

  //自定义的迭代器高效遍历工具

  for(;it!=mlist.end();it++)

  {

  cout《*it《" ";

  }

  cout《ENDL; LsList<int mlist.insert(7,2); 插入元素 cout《?在第2个元素之前插入元素7: 《endl;>::Iter itr = mlist.begin();

  for(;itr!=mlist.end();itr++)

  {

  cout《*itr《" ";

  }

  cout《ENDL;

  { int cout《?list的元素个数为: 《mlist.GetSize()《endl;

  cout《endl; ; }

  pre }< mlist.clear();

  清空整个线性表 cout《?清空整个线性表: 《endl;

  cout《*itr《? for(;itr!="mlist.end();

  itr++)" itr="mlist.begin();" mlist.dele(ia,2); ia;

  删除元素 cout《?删除第二个元素: 《endl;><BR>

  <IMG style="WIDTH: 630px; DISPLAY: inline; HEIGHT: 403px" alt="" src="

  <BR>

  <P></P>

        

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++实现静态链表 下一篇C++Tab键实现自动补全输入功能

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)