-
Notifications
You must be signed in to change notification settings - Fork 0
/
pile.cpp
85 lines (65 loc) · 1.51 KB
/
pile.cpp
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
#include "pile.h"
Pile* Pile::instance = nullptr;
Pile::Pile(): message(""), maxAffiche(0) {
}
Pile::~Pile() {
libererInstance();
}
Pile* Pile::getInstance() {
if (!instance)
instance = new Pile();
return instance;
}
void Pile::libererInstance() {
if (instance)
delete instance;
}
QString Pile::getMessage() const {
return message;
}
void Pile::setMessage(const QString& msg) {
message = msg;
}
void Pile::setMaxAffiche(unsigned int i) {
maxAffiche = i;
}
unsigned int Pile::getMaxAffiche() const {
return maxAffiche;
}
void Pile::push(Litteral *lit) {
stack.push(lit);
emit modificationEtat();
}
Litteral* Pile::pop() {
if(stack.length() == 0)
throw ComputerException("Erreur : Pile vide");
else
return stack.pop();
}
Litteral* Pile::top() const {
if(stack.length() == 0)
throw ComputerException("Erreur : Pile vide");
else
return stack.top();
}
int Pile::getLength() const {
return stack.length();
}
bool Pile::isEmpty() const {
return stack.isEmpty();
}
QStack<Litteral*>::const_iterator Pile::getIteratorBegin() const {
QStack<Litteral*>::const_iterator i = stack.constBegin();
return i;
}
QStack<Litteral*>::const_iterator Pile::getIteratorEnd() const {
QStack<Litteral*>::const_iterator i = stack.constEnd();
return i;
}
Memento* Pile::createMemento() const {
return new Memento(stack);
}
void Pile::reinstateMemento(Memento* mem) {
stack = mem->state;
emit modificationEtat();
}