单向链表总处于排序
来源:互联网 发布:电商项目面试题java 编辑:程序博客网 时间:2024/04/30 00:16
template <typename Object> struct Node { Object data; Node * next; Node ( const Object & d = Object(), Node *n = NULL ) : data(d) , next(n) {} };
template <typename Object>class singleList{ public: singleList( ) { init(); } ~singleList() { eraseList(head); } singleList( const singleList & rhs) { eraseList(head); init(); *this = rhs;} bool add(Object x) { if (contains(x)) return false;else { Node<Object> *ptr = head->next; Node<Object>* trailer = head; while(ptr && ptr->data < x) { trailer = ptr; ptr = ptr->next; } trailer->next = new Node<Object> (x); trailer->next->next = ptr; theSize++; } return true;} bool remove(Object x) { if (!contains(x)) return false;else { Node<Object>*ptr = head->next; Node<Object>*trailer; while(ptr->data != x) { trailer = ptr;ptr=ptr->next; } trailer->next = ptr->next; delete ptr; theSize--; } return true; }int size() { return theSize;}void print(){ Node<Object> *ptr = head->next; while (ptr != NULL) { cout<< ptr->data<<" "; ptr = ptr->next; } cout<<endl;}bool contains(const Object & x){ Node<Object> * ptr = head->next; while (ptr != NULL && ptr->data <= x ) { if (x == ptr->data) return true; else ptr = ptr-> next; } return false; }void init() { theSize = 0; head = new Node<Object>; head-> next = NULL;} void eraseList(Node<Object> * h) { Node<Object> *ptr= h; Node<Object> *nextPtr; while(ptr != NULL)
{ nextPtr = ptr->next; delete ptr; ptr= nextPtr;} }; private: Node<Object> *head; int theSize;};
0 0
- 单向链表总处于排序
- 排序--(单向)冒泡排序
- 单向链表排序
- 冒泡排序(单向)
- 单向链表建立 排序
- 单向链表的排序
- 单向链表归并排序
- 单向链表快速排序
- alg : 单向链表排序
- 单向链表归并排序
- 单向链表快速排序
- 单向链表归并排序
- 快速排序(单向型)
- 单向链表排序-归并排序
- 单向链表排序:快速排序和归并排序
- T-SQL单向冒泡排序算法
- 单向链表排序(冒泡)
- 单向链表实现倒排序
- CXF 拦截器预处理request、response消息
- 使用 ZooKeeper 同步集群配置
- 黑马程序员----java基础之面向对象二
- android IPC通信中的UID和PID识别 -》 clearCallingIdentity 的作用
- 无线路由对桥接和中继之间区别的理解
- 单向链表总处于排序
- IMP-00010: 不是有效的导出文件,头部验证失败。
- treap树模版
- 嵌套类与局部类
- 查看windows操作系统的默认编码
- android layout 并排布局
- linux 环境下c,c++编程(一):GCC环境搭建及基本介绍
- 排序算法《一》冒泡排序
- 查找附近点