-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQues-16(a).cpp
79 lines (74 loc) · 1.84 KB
/
Ques-16(a).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
/*
QUESTION-16:
Write a program to reverse the order of the elements in the stack using additional stack.
SOLUTION:
*/
#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<<"\nThe reversed data in the stack is:\n";
while(top!=NULL)
{
cout<<top->data<<"\n^"<<endl;
top=top->prev;
}
}
int empty()
{
if(top==NULL)
return -1;
else
return 1;
}
};