-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackoperations.cpp
80 lines (72 loc) · 1.07 KB
/
stackoperations.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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int max1=100;
int top = -1;
int top1 = -1;
int stack1[100];
int stack2[100];
void push(int x)
{
if(top>max1)
{
cout<<"Stack Full!!";
}
else
{
if(top==-1)
{
top = top+1;
top1 = top1+1;
stack1[top]=x;
stack2[top1]=x;
}
else
{
top = top+1;
stack1[top]=x;
if(stack2[top1]<x)
{
int k = stack2[top1];
top1 = top1+1;
stack2[top1] = k;
}
else
{
top1 = top1+1;
stack2[top1]=x;
}
}
}
}
void pop()
{
if(top<0)
cout<<"stack underflow";
else
{
int ele = stack1[top];
cout<<"element popped"<<" "<<ele<<endl;
top = top-1;
top1 = top1-1;
}
}
int min()
{
return stack2[top1];
}
int main()
{
push(40);
push(20);
push(30);
push(10);
pop();
pop();
push(60);
push(25);
int z = min();//get minimum
cout<<"minimum elememt:"<<" "<<z<<endl;
for(int i = top;top>=0;top--)
cout<<stack1[top]<<" ";
}