-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.cpp
More file actions
56 lines (54 loc) · 1.16 KB
/
Copy pathhistory.cpp
File metadata and controls
56 lines (54 loc) · 1.16 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
#include "history.h"
history::history() {
head = nullptr;
tail = nullptr;
N = 0;
}
history::~history() {
element* el;
while(head){
el = head->next;
delete head;
head = el;
}
}
element* history::delBattle() {
element * el;
if(tail){
el = tail;
if(el == head) head= tail = nullptr;
else {
tail = head;
while(tail ->next != el) tail = tail ->next;
tail->next = nullptr;
}
N--;
return el;
}
else return nullptr;
}
element* history::addBattle(string battle_result) {
auto* ELEMENT = new element;
ELEMENT->result = battle_result;
ELEMENT->next = head;
head = ELEMENT;
if(!tail) tail = head;
N++;
if(N >= 11) {
delBattle();
}
return head;
}
void history::display_history() {
element* el;
int i = 1;
if(!head) cout << "there is no battle yet" << endl;
else{
el = head;
while(el){
cout << "battle no.: " << i <<" " << el->result << endl;
el = el ->next;
i++;
}
}
}