-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
106 lines (93 loc) · 2.16 KB
/
stack.h
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
#include <bits/stdc++.h>
using namespace std;
class bucket // Linked List class for bucket as to implement Stack Properties
{
public:
int data;
bucket *next;
};
bucket *top; // treating our baskets as stack. hence variable for maintaining stack properties
void push(int data) // for pushing baskets when program starts
{
bucket *temp = new bucket();
if (!temp) // overflow condition for stack
{
cout << "\nStack Overflow ! No more baskets can be stacked.\n";
exit(1);
}
else // allocating basket number and maintaining stack of baskets in this body
{
temp->data = data;
temp->next = top;
top = temp;
}
}
bool isempty() // function to check avalability of baskets.
{
if (top == NULL)
{
return true;
}
else
{
return false;
}
}
int topElement() // function to check 1st reachable basket
{
if (isempty() == true)
{
cout << "Stack is empty ! Please add baskets to start shoppping.\n";
exit(1);
}
return top->data;
}
void customerProceed() // function for customer operations
{
bucket *temp = new bucket(); // basket for customer
if (isempty() == true) // checking underflow
{
cout << "Stack is empty ! Please add baskets to start shoppping.\n";
exit(1);
}
else // taking basket and making it free from meomry in this body.
{
temp = top;
top = top->next;
temp->next = NULL;
free(temp);
}
cout << "Your basket No is :" << top->data << endl; // labeling basket index
// basket design
cout << "Welcome To Our Pharmacy !\n\n" << endl;
cout << " '" << endl;
cout << " ' ' " << endl;
cout << " ' ' " << endl;
cout << " ' ' " << endl;
cout << " ' ' " << endl;
cout << " || ||" << endl;
cout << " || ||" << endl;
cout << " || ||" << endl;
cout << " ||---------||" << endl;
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
}
void display()
{
bucket *temp = new bucket(); // making new basket object
if (isempty() == true) // underflow check
{
cout << "\nStack Underflow ! There are no baskets available.\n";
exit(1);
}
else // printing baskets labels in this body
{
temp = top;
while (temp != NULL)
{
cout << temp->data << " ";
temp = temp->next;
}
}
}