-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackTest.cpp
More file actions
63 lines (52 loc) · 1.46 KB
/
stackTest.cpp
File metadata and controls
63 lines (52 loc) · 1.46 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
57
58
59
60
61
62
#include <iostream>
#include "myStack.h"
using namespace std;
void postfixTest() {
myStack operandStack(100);
cout << "Please enter the operands (integers 1~9) and operators (+, -, *, /) one by one..." << endl;
cout << "and enter '=' to indicate the end of the expression and to output the result." << endl;
while(1){
char inputHolder;
cin >> inputHolder;
// TODO
}
}
int main()
{
cout << "Testing the basic functions of the stack..." << endl;
cout << "Please enter the max capacity of the testStack: ";
int testSize;
cin >> testSize;
myStack testStack(testSize);
cout << "Testing..." << endl;
while(1) {
cout << "Please enter 'p' for push, 'o' for pop, 'e' for exit: ";
char userChoice;
cin >> userChoice;
if(userChoice == 'e')
break;
switch (userChoice) {
case 'p':
if(!testStack.isFull()) {
cout << "Please enter the integer you would like to push: ";
int userInt;
cin >> userInt;
testStack.push(userInt);
}
else
cout << "Nothing has been pushed in. The stack is full!" << endl;
break;
case 'o':
if(!testStack.isEmpty())
cout << testStack.pop() << " has been popped out" << endl;
else
cout << "Nothing has been popped out. The stack is empty!" << endl;
break;
default:
cout << "Illegal user-input character. Please try again." << endl;
}
}
cout << "Now, start to use a stack to evaluate postfix expressions..." << endl;
postfixTest();
return 0;
}