forked from Zemux1613/Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
55 lines (34 loc) · 835 Bytes
/
Main.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 "Main.h"
int stackCounter = 0;
// direkt alles mit 0 inizialisieren
float stack[ArraySize] = { 0.0f };
void Inizialise() {
stackCounter = 0;
for (int i = 0; i < ArraySize; i++) {
stack[i] = 0.0f;
}
}
void push(float value)
{
// If the stack is not the maximum size, it can be added to the stack.
if (stackCounter < ArraySize) {
stack[stackCounter] = value;
stackCounter++;
}
}
float pop() {
--stackCounter;
float lastValue = stack[stackCounter];
return lastValue;
}
int main() {
// Inizialise values at the stack
Inizialise();
// push 2.2 on the stack
push(2.2);
// push 1.2 on the stack
push(1.2);
// remove the last element and get the value of last element of the stack
float pop1 = pop();
return 0;
}