NANA
首页
模块
类
文件
文件列表
文件成员
NANA
modules
graph
include
graph
list.hpp
浏览该文件的文档.
1
#pragma once
16
namespace
NANA {
17
namespace
GRAPH {
18
21
22
23
template
<
typename
T>
24
struct
ListNode
25
{
26
ListNode
* m_next;
27
ListNode
* m_prev;
28
T m_data;
29
30
ListNode
(T x)
31
:m_next(
nullptr
)
32
, m_prev(
nullptr
)
33
, m_data(x)
34
{}
35
};
36
41
template
<
typename
T>
42
class
CicList
{
43
typedef
ListNode<T>
Node
;
44
public
:
45
CicList
()
46
:_head(
new
Node
(T()))
47
{
48
_head->_next = _head;
49
_head->_prev = _head;
50
}
51
52
53
virtual
~CicList
()
54
{
55
Node
* tmp = _head->_next;
56
while
(tmp != _head)
57
{
58
Node
* cur = tmp->_next;
59
delete
tmp;
60
tmp = cur;
61
}
62
}
63
64
void
setHead(T x) {
65
_head->_data = x;
66
}
67
68
void
push_front(
const
T& x) {
69
Insert(_head->_next, x);
70
}
71
72
void
push_back(
const
T& x) {
73
Insert(_head->_prev, x);
74
}
75
76
77
private
:
78
//插入一个元素
79
void
Insert(
Node
* pos, T x)
80
{
81
Node
* newnode =
new
Node
(x);
82
newnode->m_next = pos;
83
pos->m_prev->m_next = newnode;
84
newnode->m_prev = pos->m_prev;
85
pos->m_prev = newnode;
86
}
87
//data
88
Node
* m_head;
89
};
90
95
template
<
typename
T>
96
class
CList
{
97
typedef
ListNode<T>
Node
;
98
public
:
99
100
101
protected
:
102
};
103
104
105
106
108
109
}
110
}
NANA::GRAPH::CList
普通链表,不同于循环链表
Definition:
list.hpp:96
NANA::GRAPH::CicList
双向循环链表
Definition:
list.hpp:42
NANA::GRAPH::ListNode
Definition:
list.hpp:25
制作者
1.9.2