-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.h
58 lines (46 loc) · 916 Bytes
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef CPP_LIST_H
#define CPP_LIST_H
template <class T>
class list {
T m_content;
list* m_next;
public:
list(const T& c, list* next = 0) : m_content(c), m_next(next) { };
list( T& c, list* next = 0) : m_content(c), m_next(next) { };
T& content() { return m_content; };
const T& content() const { return m_content; };
static list* push_back(list* head, list* n)
{
list* k = head;
if (! k)
return n;
while (k->m_next)
k = k->m_next;
k->m_next = n;
return head;
}
static int length(list* ls)
{
int n = 0;
for ( ; ls; ls = ls->next())
n++;
return n;
}
static void free(list* p)
{
list* n;
for (/* */; p; p = n)
{
n = p->m_next;
delete p;
}
}
static list* pop(list* p)
{
list* tail = p->next();
delete p;
return tail;
}
list* next() { return m_next; };
};
#endif