-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGENERIC MULTIWAY STACK.CPP
112 lines (103 loc) · 1.5 KB
/
GENERIC MULTIWAY STACK.CPP
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
103
104
105
106
107
108
109
110
111
112
#include<iostream>
using namespace std;
template<class M>
class stack
{
M* st;
int length,top,bottom;
public :
stack(int m=10)
{
length=m;
st= new M[m];
top=0;
bottom=length;
}
void push(M m=0)
{
if(top==length)
{
cout<<"STACK OVERFLOWING. CANN'T ADD MORE ELEMENTS.."<<endl;
return;
}
st[top++]=m;
}
void insert(M m=0)
{
if(top==bottom)
{
cout<<"STACK OVERFLOWING. CANN'T ADD MORE ELEMENTS.."<<endl;
return;
}
st[--bottom]=m;
}
M pop()
{
M p;
if(top==0)
{
cout<<"STACK EMPTY.. CANN'T POP ANYMORE";
return 0;
}
p=st[--top];
return p;
}
M put_off()
{
M p;
if(bottom==length)
{
cout<<"STACK EMPTY.. CANN'T POP ANYMORE"<<endl;
return 0;
}
p=st[bottom++];
return p;
}
void display()
{
for(int i=top-1;i>=0;i--)
{
cout<<st[i]<<endl;
}
}
void out()
{
for(int i=bottom;i<length;i++)
{
cout<<st[i]<<endl;
}
}
};
int main()
{
cout<<endl;
cout <<"I AM HERE GUYS."<<endl;
cout<<endl;
stack <char>one;
one.push(77);
one.push(57);
one.push(65);
one.display();
cout<<endl;
cout<<one.pop()<<" IS GOING TO BE DELETED"<<endl;
cout<<endl;
one.display();
cout<<endl;
cout <<"I AM HERE GUYS."<<endl;
cout<<endl;
one.insert(75);
one.insert(87);
one.insert('S');
one.insert(50);
one.out();
cout<<endl;
cout<<one.put_off()<<" IS GOING TO BE DELETED"<<endl;
cout<<endl;
//one.put_off();
//one.put_off();
//one.put_off();
//one.put_off();
one.out();
cout<<endl;
return 0;
}