-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.cpp
More file actions
41 lines (28 loc) · 1002 Bytes
/
stack_test.cpp
File metadata and controls
41 lines (28 loc) · 1002 Bytes
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
#include <iostream>
#include "stack.h"
using namespace std;
int main(int argc, char* argv[]){
//Create a stack - check its size, it should be empty
Stack<int> stack1;
cout << "Size: " << stack1.size() << endl << "Empty? " << stack1.empty() << endl;
//Add something to the stack - size should increase, it should no longer be empty
stack1.push(1);
cout << "Size: " << stack1.size() << endl << "Empty? " << stack1.empty() << endl;
for (int i = 2; i <= 10; i ++){
stack1.push(i);
}
cout << "Size: " << stack1.size() << endl << "Empty? " << stack1.empty() << endl;
//Check what is on top of the stack
cout << "This is on top: " << stack1.top() << endl;
//Remove the item from the top of the stack
for (int i = 0; i < 3; i++){
stack1.pop();
}
cout << "This is on top: " << stack1.top() << endl;
cout << "Size: " << stack1.size() << endl << "Empty? " << stack1.empty() << endl;
cout << "Testing errors\n";
for (int i = 1; i <= 7; i++){
stack1.pop();
}
stack1.top();
}