当前位置: 首页 > news >正文

淄博网站开发招聘搜狗站长工具

淄博网站开发招聘,搜狗站长工具,wordpress分类关键字,微信小程序哪里找单向链表 link list t数组的局限:编译期就需要知道大小; 内存连续,插入困难 // 链表节点类 包含一个信息 和指向下一个 节点的指针clas IntLLNode{public:IntLLNode(){// 默认构造函数 没有info信息nextPtr_ 0;// 空指针}IntLLNode(int …

单向链表  link list

t数组的局限:编译期就需要知道大小; 内存连续,插入困难

    // 链表节点类 包含一个信息 和指向下一个 节点的指针clas IntLLNode{public:IntLLNode(){// 默认构造函数   没有info信息nextPtr_ = 0;// 空指针}IntLLNode(int data, IntLLNode* in = 0){// 第二个构造函数info_    = data;nextPtr_ = in;}public:int info_;          // 包含一个信息          对用户很重要IntLLNode* nextPtr_;// 指向下一个 节点的指针  用于将节点连接起来组成链表}// 定义一个 节点指针IntLLNode* pt = new IntLLNode(10);//新建一个节点 其地址 赋给一个指向 IntLLNode 的指针 pt////   [pt]  ----> |  10 | 也就是 pt->info_   也就是 (*pt).info_//               |  \  | 也就是 pt->nextPtr_ 也就是 (*pt).nextPtr_ // 再定义一个节点pt->nextPtr  = new IntLLNode(30);//新建一个节点 其地址 赋给一个指向 IntLLNode 的指针 pt->nextPtr_////   [pt]  ----> |  10 |  //               |     |  -----> | 30 | 也就是 pt->nextPtr_->info_//                               | \  | 也就是 pt->nextPtr_->nextPtr_// 再定义一个节点pt->nextPtr_->nextPtr_  = new IntLLNode(50);//新建一个节点 其地址 赋给一个指向 IntLLNode 的指针 pt->nextPtr_->nextPtr_////   [pt]  ----> |  10 |  //               |     |  -----> | 30 |  //                               |    | ------> | 50 | 也就是  pt->nextPtr_->nextPtr_->info_//                                              |  \ | 也就是  pt->nextPtr_->nextPtr_->nextPtr_

使用 头结点和尾节点来存储链表结构

 //************************  intSLList.h  **************************// 单链表 实现类 #ifndef INT_LINKED_LIST#define INT_LINKED_LIST// 单个节点// 定义一个 节点指针// IntLLNode* pt = new IntLLNode(10);//新建一个节点 其地址 赋给一个指向 IntLLNode 的指针 pt////   [pt]  ----> |  10 | 也就是 pt->info_   也就是 (*pt).info_//               |  \  | 也就是 pt->nextPtr_ 也就是 (*pt).nextPtr_  class IntSLLNode {public:IntSLLNode() {// 默认构造函数   没有info信息next = 0;// 空指针}IntSLLNode(int data, IntSLLNode *ptr = 0) {// 第二个构造函数info = data; next = ptr;}public:    int info;         // 包含一个信息          对用户很重要IntSLLNode *next; // 指向下一个 节点的指针  用于将节点连接起来组成链表};// 链表 类  保存了一个 头节点 和 一个尾节点 class IntSLList {public:IntSLList() {// 默认构造函数  这里定义和实现 head = tail = 0;// 节点 和 一个尾节点 指针赋值为 空 }~IntSLList();// 默认析构函数  只有定义 实现在 cpp文件中 int isEmpty() {//为空链表是否 return head == 0;}void addToHead(int);   // 从头部添加 节点 void addToTail(int);   // 从尾部添加 节点 int  deleteFromHead(); // 从头部删除 节点 并返回该节点的信息 int  deleteFromTail(); // 从尾部删除 节点 并返回该节点的信息 void deleteNode(int);//删除 bool isInList(int) const;void printAll() const;//打印所有的节点的信息   private:IntSLLNode *head, *tail;// 保存了一个 头节点 和 一个尾节点};

#endif

实现类cpp intSLList.cpp

头部插入节点   head 和 tail  仅仅是保存了 一个(节点)存储的地址

   head ---> | 5 |  |   | ---> | 7 ||   | --->  |  4 | <-------- tail|    |新建一个节点                                 | 9 |  head ---> | 5 |  |   |            |   | ---> | 7 ||   | --->  |  4 | <-------- tail|    |   新节点指向 head 指向的地址   new IntSLLNode9, head);| 9 |  head ---> | 5 |  |   | ------->   |   | ---> | 7 ||   | --->  |  4 | <-------- tail原头结点指向新节点  head = new IntSLLNode(9,head);head --->  |   | | 9 |  |   | -------> | 5 |  |   | ---> | 7 ||   | --->  |  4 | <-------- tail

|   |

尾部插入一个节点

 head ---> | 5 |  |   | ---> | 7 ||   | --->  |  4 | <-------- tail|    |尾部新建一个节点     new IntSLLNode(9);                             head ---> | 5 |  |   | ---> | 7 ||   | --->  |  4 | <-------- tail|    |                 | 9 |   | \ |                                 tail指向的节点 指向这个新节点   tail->next = new IntSLLNode(9)head ---> | 5 |  |   | ---> | 7 ||   | --->  |  4 | <-------- tail|    | -------->   | 9 |   | \ | 尾节点tail 指向新的 尾节点   tail = tail->next;head ---> | 5 |  |   | ---> | 7 ||   | --->  |  4 | |    | -------->  | 9 |   <-------- tail| \ |                                 

双向向链表  link list  节点同时包含 指向前驱节点的指针 也包含 指向后继节点的指针

双向向链表

跳跃链表

跳跃链表

标准库中的链表 list #include

 //一些成员函数assign(iterator first, iterator last) 删除所有节点,在first到last插入元素assign(size_type n, el) 删除所有节点,向其中插入n个elback()  尾节点元素front() 第一个节点元素clear() 删除所有节点empty() 判断是否为空erase() 删除一个节点insert() 插入一个元素pop_back() 删除最后一个节点pop_front() 删除第一个节点push_back() 在表尾插入push_front() 在表头插入sort()       排序swap()      与另一个链表互换unique()   从有序链表中删除重复的元素

测试代码

#include <iostream>
#include <list>//链表 
#include <algorithm>// 算法 
#include <deque>//队列 
#include <functional>using namespace std;// 打印链表每一个元素 
template<class T>
void printList(const list<T>& lst, char *s) {cout << s << ":  ";for (typename list<T>::const_iterator i = lst.begin(); i != lst.end(); ++i)cout << *i << ' ';cout << endl;
}int main() {list<int> lst1;// 创建空链表                     printList(lst1,"lst1");     // lst1 is emptylist<int> lst2(3,7);            printList(lst2,"lst2");     // lst2 = (7 7 7)for (int j = 1; j <= 5; j++)// lst1 = (1 2 3 4 5)lst1.push_back(j);//尾后插入元素 list<int>::iterator i1 = lst1.begin(), i2 = i1, i3;i2++; i2++; i2++;list<int> lst3(++i1,i2);        printList(lst3,"lst3");     // lst3 = (2 3)list<int> lst4(lst1);printList(lst4,"lst4");     // lst4 = (1 2 3 4 5)i1 = lst4.begin();lst4.splice(++i1,lst2);         printList(lst2,"lst2");     // lst2 is emptyprintList(lst4,"lst4");     // lst4 = (1 7 7 7 2 3 4 5)lst2 = lst1;printList(lst2,"lst2");     // lst2 = (1 2 3 4 5)i2 = lst2.begin();lst4.splice(i1,lst2,++i2);      printList(lst2,"lst2");     // lst2 = (1 3 4 5)printList(lst4,"lst4");     // lst4 = (1 7 7 7 2 2 3 4 5)i2 = lst2.begin();i3 = i2;lst4.splice(i1,lst2,i2,++i3);printList(lst2,"lst2");     // lst2 = (3 4 5)printList(lst4,"lst4");     // lst4 = (1 7 7 7 2 1 2 3 4 5)lst4.remove(1);         printList(lst4,"lst4");     // lst4 = (7 7 7 2 2 3 4 5)lst4.sort();                            printList(lst4,"lst4");     // lst4 = (2 2 3 4 5 7 7 7)lst4.unique();                          printList(lst4,"lst4");     // lst4 = (2 3 4 5 7)lst1.merge(lst2);                        printList(lst1,"lst1");     // lst1 = (1 2 3 3 4 4 5 5),printList(lst2,"lst2");     // lst2 is emptylst3.reverse();                         printList(lst3,"lst3");     // lst3 = (3 2)     lst4.reverse();printList(lst4,"lst4");     // lst4 = (7 5 4 3 2)lst3.merge(lst4,greater<int>());  printList(lst3,"lst3");     // lst3 = (7 5 4 3 3 2 2)printList(lst4,"lst4");     // lst4 is emptylst3.remove_if(bind2nd(not_equal_to<int>(),3));printList(lst3,"lst3");     // lst3 = (3 3)lst3.unique(not_equal_to<int>());printList(lst3,"lst3");     // lst3 = (3 3)return 0;
}
http://www.mmbaike.com/news/107627.html

相关文章:

  • .net做的网站打开速度缓慢关键词热度
  • 网站优化关键词网络营销方法
  • pc端网站自适应代码品牌营销策略四种类型
  • 网站升级及政务新媒体建设方案网站设计优化
  • 网站线框图怎样做手机网页制作软件
  • wordpress无法将图片上传只要做好关键词优化
  • 苏宁易购如何进行网站的建设和维护seo兼职怎么收费
  • 建设项目网站备案申请表企业线上培训课程
  • 替人做赌彩网站重庆seo黄智
  • 选择网站建设系统百度趋势搜索
  • 西安给公司做网站网盘搜索神器
  • 阿里巴巴国际站下载卖家版公司网站建设服务
  • 广东网站建设人员seo推广 课程
  • 怎么看公司网站是哪里做的app广告投放价格表
  • 什么是专门型的网站博为峰软件测试培训学费
  • 网站三级导航栏代码腾讯企点注册
  • 做网站的前台用什么工具产品软文是什么意思
  • 做二手手机的网站有哪些建网站赚钱
  • 网站改版有什么影响进入百度官网首页
  • 粉丝网站制作市场调研报告范文3000字
  • 日照疫情最新消息深圳网站设计专业乐云seo
  • 企业网站开发的文献综述sem推广竞价
  • 教育类app开发价格表北京seo多少钱
  • 搜索附近离得近的昆明seo关键字推广
  • 小程序免费制作平台系统关键词优化公司哪家好
  • 广州网站制作网页聊石家庄seo
  • 网页设计公司员工seo专业技术培训
  • 网投怎么做网站哪个软件可以自动排名
  • wordpress子菜单位置分离沈阳seo关键词
  • 有没有教做化学药品的网站上海推广服务