-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhisto.cpp
More file actions
104 lines (90 loc) · 2.14 KB
/
histo.cpp
File metadata and controls
104 lines (90 loc) · 2.14 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "histo.hpp"
namespace listes{
template <class T> int base<T>::set( T val){
value = val;
return 1;
}
template <class T> int base<T>::next( base<T>* n){
nex = n;
return 1;
}
template <class T> int base<T>::previous( base<T>* p){
prev = p;
return 1;
}
template <class T> T base<T>::get(){
return value;
}
template <class T> base<T> * base<T>::get_next(){
return nex;
}
template <class T> base<T> * base<T>::get_prev(){
return prev;
}
template <class T> base<T>::base()
{
prev = nex = NULL;
}
template <class T> base<T>::base(T val)
{
prev = nex = NULL;
value = val;
}
template <class T> base<T>::~base()
{
}
bool histo::empty(){
return length == 0;
}
void histo::push(std::string a){
last->next(new base<std::string>);
last->get_next()->set(a);
last->get_next()->previous(last);
last = last->get_next();
length ++;
if(maxLength !=0){
if(length > maxLength){
length --;
first = first->get_next();
}
}
}
std::string histo::pop(){
std::string current;
if(length > 0){
current = last->get();
length --;
last = last->get_prev();
//free next
delete last->get_next();
last->next(NULL);
}
return current;
}
std::string histo::pop(long p){
std::string current;
while(p-->0){
if(length > 0){
current = last->get();
length --;
last = last->get_prev();
//free next
delete last->get_next();
last->next(NULL);
}
else
{
break;
}
};
return current;
}
histo::histo()
{
first = new base<std::string>;
last = first;
length = 0;
maxLength = 0;
}
//string
}