-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack array.cpp
More file actions
102 lines (54 loc) · 1.58 KB
/
stack array.cpp
File metadata and controls
102 lines (54 loc) · 1.58 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// stack array.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <assert.h>
#include "stackType.h"
using namespace std;
void testCopyConstructor(stackType<int> otherStack);
int main()
{
stackType<int>stack(50);
stackType<int>copyStack(50);
stackType<int> dummyStack(100);
int x;
stack.push(66);
stack.push(33);
stack.push(88);
stack.push(55);
cout << "display the contants of Stack\n"; cout << " from first element to last " << endl;
stack.displaystack();
cout << "\nThe Top Element in the Stack is " << stack.top();
cout << endl;
cout << "\ndisplay the contants of Stack \n"; cout << "from last element to first \n"; cout << "with the using of POP function " << endl; while (!stack.isEmptyStack())
{
stack.pop(x);
cout << " " << x;
}
cout << "\n\n\n" << endl;
copyStack = stack;
while (!copyStack.isEmptyStack())
{
copyStack.pop(x);
cout << "Inside copyStack " << x << endl;
}
copyStack =stack;
testCopyConstructor(stack);
if (!stack.isEmptyStack())
{
cout << "Original stack is not empty" << endl;
stack.pop(x);
cout << "Top element of the original stack :" << x << endl;
}
dummyStack = stack;
system("pause");
return 0;
}
void testCopyConstructor(stackType<int> otherStack) {
int x;
if (!otherStack.isEmptyStack())
{
cout << "Other stack is not empty" << endl;
otherStack.pop(x);
cout << "Top element of the other stack: " << x << endl;
}
}