-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.cpp
More file actions
99 lines (95 loc) · 1.77 KB
/
Copy pathtest.cpp
File metadata and controls
99 lines (95 loc) · 1.77 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
// CPP program to demonstrate working of STL stack
#include<iostream>
using namespace std;
class Stack
{
public:
static int stack[1000][3];
int n;
int top;
Stack()
{
n=1000;
top=-1;
}
void push(int val[3])
{
if(top>=n-1)
cout<<"Stack Overflow"<<endl;
else {
top++;
stack[top][0]=val[0];
stack[top][1]=val[1];
stack[top][2]=val[2];
}
}
void pop() {
if(top<=-1)
cout<<"Stack Underflow"<<endl;
else {
cout<<"The popped element is "<< stack[top] <<endl;
top--;
}
}
int topx(){
return stack[top][0];
}
int topy(){
return stack[top][1];
}
int topval(){
return stack[top][2];
}
void display() {
if(top>=0) {
cout<<"Stack elements are:";
for(int i=top; i>=0; i--)
cout<<stack[i]<<" ";
cout<<endl;
} else{
cout<<"Stack is empty";
}
}
};
int main() {
Stack stack;
int* a;
a=5;
stack.push(a);
/*
int ch;
int val[3];
cout<<"1) Push in stack"<<endl;
cout<<"2) Pop from stack"<<endl;
cout<<"3) Display stack"<<endl;
cout<<"4) Exit"<<endl;
do {
cout<<"Enter choice: "<<endl;
cin>>ch;
switch(ch) {
case 1: {
cout<<"Enter value to be pushed:"<<endl;
cin>>val[3];
push(val);
break;
}
case 2: {
pop();
break;
}
case 3: {
display();
break;
}
case 4: {
cout<<"Exit"<<endl;
break;
}
default: {
cout<<"Invalid Choice"<<endl;
}
}
}while(ch!=4);
*/
return 0;
}