blob: f88ca36d8cbf20f008c553869e1a458daad066fa (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#include "List.hpp"
ft::List::List(const allocator_type& alloc = allocator_type())
{
front = nullptr;
back = nullptr;
size = 0;
}
ft::List::~List()
{
while (size > 0)
pop_front();
}
ft::List::bool empty() const
{
return front == nullptr;
}
ft::List::size_type size() const
{
return size;
}
ft::List::reference front()
{
return *front;
}
ft::List::reference back()
{
return *back;
}
ft::List::void push_front (const value_type& val)
{
PrivateList *nfront = new PrivateList(val);
nfront->next = front;
front = nfront;
if (back == nullptr)
back = front;
size++;
}
ft::List::void pop_front()
{
t_llist *nfront = front->next;
if (size == 1)
back = nullptr;
delete front;
front = nfront;
size--;
}
ft::List::void push_back (const value_type& val)
{
PrivateList *nback = new PrivateList(val);
if (empty())
{
back = nback;
front = back;
return;
}
back->next = nback;
back = nback;
size++;
}
ft::List::void pop_back()
{
t_llist *tmp = front;
while (tmp->next != back)
tmp = tmp->next;
delete back;
back = tmp;
}
ft::List::PrivateList::PrivateList(const value_type& val);
{
next = nullptr;
val = val;
}
ft::List::PrivateList::~PrivateList()
{
delete val;
}
|