-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackb.cpp
More file actions
94 lines (82 loc) · 1.15 KB
/
stackb.cpp
File metadata and controls
94 lines (82 loc) · 1.15 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
#include <iostream>
#include <climits>
using namespace std;
class stack{
public:
struct node
{
int data;
node* next;
};
struct minimum
{
int value;
minimum *next;
};
stack(){
head = NULL;
first = NULL; //use bigger see range
}
void push(int val){
node *n = new node();
n->data = val;
n->next=head;
head=n;
if(first ==NULL || first->value > val){
minimum *m = new minimum();
m->value = val;
m->next = first;
first = m;
}else{
minimum *m = new minimum();
m->value = first->value;
m->next = first;
first = m;
}
}
void pop(){
head=head->next;
/*
if(n->data == first->value){
first = first->next;
}*/
first = first->next;
}
int peek(){
return head->data;
}
bool empty(){
if(head==NULL)
return true;
return false;
}
void dispay() const{
node *n;
n=head;
while(n!=NULL){
cout<<n->data<<" ";
n=n->next;
}
}
int min(){
if(first==NULL){
return INT_MAX;
}
return first->value;
}
private:
node *head;
minimum *first;
};
int main(){
stack a;
a.push(8);
a.push(4);
a.push(7);
a.push(4);
a.pop();
a.dispay();
cout<<endl;
cout<<a.min();
return 0;
}