TheAlgorithms-C-Plus-Plus/data_structure/stk/test_stack.cpp

59 lines
1.6 KiB
C++
Raw Normal View History

2020-01-13 08:53:13 +08:00
#include <iostream>
#include "stack.cpp"
#include "stack.h"
2020-01-13 08:53:13 +08:00
using namespace std;
int main()
{
stack<int> stk;
cout << "---------------------- Test construct ----------------------"
<< endl;
2020-01-13 08:53:13 +08:00
stk.display();
cout << "---------------------- Test isEmptyStack ----------------------"
<< endl;
if (stk.isEmptyStack())
cout << "PASS" << endl;
2020-01-13 08:53:13 +08:00
else
cout << "FAIL" << endl;
2020-01-13 08:53:13 +08:00
cout << "---------------------- Test push ----------------------" << endl;
cout << "After pushing 10 20 30 40 into stack: " << endl;
2020-01-13 08:53:13 +08:00
stk.push(10);
stk.push(20);
stk.push(30);
stk.push(40);
stk.display();
cout << "---------------------- Test top ----------------------" << endl;
int value = stk.top();
if (value == 40)
cout << "PASS" << endl;
2020-01-13 08:53:13 +08:00
else
cout << "FAIL" << endl;
2020-01-13 08:53:13 +08:00
cout << "---------------------- Test pop ----------------------" << endl;
stk.display();
stk.pop();
stk.pop();
cout << "After popping 2 times: " << endl;
2020-01-13 08:53:13 +08:00
stk.display();
cout << "---------------------- Test overload = operator "
"----------------------"
<< endl;
2020-01-13 08:53:13 +08:00
stack<int> stk1;
cout << "stk current: " << endl;
2020-01-13 08:53:13 +08:00
stk.display();
cout << endl << "Assign stk1 = stk " << endl;
2020-01-13 08:53:13 +08:00
stk1 = stk;
stk1.display();
cout << endl << "After pushing 8 9 10 into stk1:" << endl;
2020-01-13 08:53:13 +08:00
stk1.push(8);
stk1.push(9);
stk1.push(10);
stk1.display();
cout << endl << "stk current: " << endl;
2020-01-13 08:53:13 +08:00
stk.display();
cout << "Assign back stk = stk1:" << endl;
stk = stk1;
stk.display();
return 0;
}