forked from sorest04/calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.cpp
55 lines (45 loc) · 764 Bytes
/
stack.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
#include "stack.h"
#include <vector>
#include <string>
#include <iostream>
Stack::Stack() {
}
void Stack::push(float flt) {
this->objs.push_back(flt);
}
float Stack::pop() {
float flt = objs.back();
objs.pop_back();
return flt;
}
float Stack::peak() {
return objs.back();
}
string Stack::getBack() {
vector<float> back;
int len;
int size = objs.size();
if(size<4) {
len = size;
}
else {
len = 4;
}
for(int x=0;x<len;x++){
back.push_back(objs.back());
objs.pop_back();
}
string str ="";
for(int x=len-1;x>=0;x--){
str+=to_string(back[x]);
str+=" | ";
}
for(int x=0;x<len;x++){
objs.push_back(back.back());
back.pop_back();
}
return str;
}
void Stack::clear() {
objs.clear();
}