-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ques-17(b).cpp
74 lines (69 loc) · 1.67 KB
/
Ques-17(b).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
#include<iostream>
#include<string.h>
using namespace std;
template<class t>
class stack
{
public:
t data;
stack *prev;
};
template<class t>
class stacks
{
//int stack[size];
stack<t> *top;
public:
stacks()
{
top=NULL;
}
void push(t n)
{
stack<t> *temp;
/*if(top==(size-1))
{
cout<<"overflow element not entered\n";
return 1;
}*/
//else
//{
temp=new stack<t>;
temp->data=n;
temp->prev=top;
top=temp;
//return 0;
//}
}
t pop()
{
t a;
if(top==NULL)
{
cout<<"underflow:\n";
return -1;
}
else
{
a=top->data;
top=top->prev;
return a;
}
}
void display()
{
cout<<"";
while(top!=NULL)
{
cout<<top->data<<"\n^\n"<<endl;
top=top->prev;
}
}
int empty()
{
if(top==NULL)
return -1;
else
return 1;
}
};