代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
双向链表
作者:
littleDog
/ 发布于
2015/6/10
/
680
#ifndef DOUBLY_LINKED_LIST #define DOUBLY_LINKED_LIST template<class T> class DLLNode { public: DLLNode() { next = prev = 0; } DLLNode(const T& el, DLLNode<T> *n = 0, DLLNode<T> *p = 0) { info = el; next = n; prev = p; } T info; DLLNode<T> *next, *prev; }; template<class T> class DoublyLinkedList { public: DoublyLinkedList() { head = tail = 0; } void addToDLLTail(const T&); T deleteFromDLLTail(); ~DoublyLinkedList() { clear(); } bool isEmpty() const { return head == 0; } void clear(); void setToNull() { head = tail = 0; } void addToDLLHead(const T&); T deleteFromDLLHead(); T& firstEl(); T* find(const T&) const; protected: DLLNode<T> *head, *tail; friend ostream& operator<<(ostream& out, const DoublyLinkedList<T>& dll) { for (DLLNode<T> *tmp = dll.head; tmp != 0; tmp = tmp->next) out << tmp->info << ' '; return out; } }; template<class T> void DoublyLinkedList<T>::addToDLLHead(const T& el) { if (head != 0) { head = new DLLNode<T>(el,head,0); head->next->prev = head; } else head = tail = new DLLNode<T>(el); } template<class T> void DoublyLinkedList<T>::addToDLLTail(const T& el) { if (tail != 0) { tail = new DLLNode<T>(el,0,tail); tail->prev->next = tail; } else head = tail = new DLLNode<T>(el); } template<class T> T DoublyLinkedList<T>::deleteFromDLLHead() { T el = head->info; if (head == tail) { // if only one DLLNode on the list; delete head; head = tail = 0; } else { // if more than one DLLNode in the list; head = head->next; delete head->prev; head->prev = 0; } return el; } template<class T> T DoublyLinkedList<T>::deleteFromDLLTail() { T el = tail->info; if (head == tail) { // if only one DLLNode on the list; delete head; head = tail = 0; } else { // if more than one DLLNode in the list; tail = tail->prev; delete tail->next; tail->next = 0; } return el; } template <class T> T* DoublyLinkedList<T>::find(const T& el) const { DLLNode<T> *tmp = head; for ( ; tmp != 0 && !(tmp->info == el); // overloaded == tmp = tmp->next); if (tmp == 0) return 0; else return &tmp->info; } template<class T> T& DoublyLinkedList<T>::firstEl() { return head->info; } template<class T> void DoublyLinkedList<T>::clear() { for (DLLNode<T> *tmp; head != 0; ) { tmp = head; head = head->next; delete tmp; } } #endif
试试其它关键字
双向链表
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
littleDog
贡献的其它代码
(
3
)
.
mysql数据批量导入导出
.
双向链表
.
2048算法类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3