-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathstack_form_scratch.cpp
More file actions
97 lines (94 loc) · 1.68 KB
/
stack_form_scratch.cpp
File metadata and controls
97 lines (94 loc) · 1.68 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
#include<iostream>
using namespace std;
class stackusingarr
{
int *data;
int capacity;
int top;
public :
stackusingarr(int size)
{
data = new int[size];
capacity=size;
top=0;
}
bool isempty()
{
return top==0;
}
void push(int x)
{
if(top==capacity)
{
cout<<"Stack full"<<endl;
}
else
{
data[top]=x;
top++;
}
}
void pop()
{
if(top==0)
{
cout<<"empty stack"<<endl;
}
else
{
top--;
}
}
int stacksize()
{
return top;
}
int topelt()
{
if(this->isempty())
{
return INT_MIN;
}
return data[top-1];
}
};
int main()
{
int choice,size;
char ch;
cout<<"enter max size of the stack";
cin>>size;
stackusingarr S(size);
do
{
cout<<"1->view size"<<endl<<"2->view top element"<<endl<<"3->Insert element"<<endl<<"4->Delete element"<<" 5->Exit"<<endl<<" enter choice:"<<endl;
cin>>choice;
if(choice==1)
{
cout<<S.stacksize()<<endl;
}
else if(choice ==2)
{
cout<<S.topelt()<<endl;
}
else if (choice==3)
{
cout<<"enter the element to be inserted"<<endl;
int x;
cin>>x;
S.push(x);
}
else if (choice==4)
{
S.pop();
}
else
{
break;
}
cout<<"do you want to continue"<<endl;
cin>>ch;
}
while (ch=='y' || ch=='Y');
return 0;
}