-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDL059ba.cpp
92 lines (91 loc) · 1.58 KB
/
DL059ba.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
81
82
83
84
85
86
87
88
89
90
91
92
// Filename: \\U2Chap09\DL059a.CPP
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
// Declares a stack structure
struct Node
{
int X, Y;
Node *Link;
};
class STACK
{
Node *Top;
public :
STACK() {Top=NULL;}
void PUSH();
void POP();
~STACK()
{
cout << "Value destroyed";
}
};
// Function body for adds stack elements
void STACK::PUSH()
{
Node *Temp;
Temp = new Node;
cin >> Temp->X;
cin >> Temp->Y;
Temp->Link = Top;
Top = Temp;
}
// Function body for delete stack elements
void STACK::POP()
{
Node *temp;
int val;
if (Top == NULL)
{
cout << "Stack Empty ";
}
else
{
temp = Top;
Top = Top->Link;
temp->Link = NULL;
delete temp;
}
}
// Main programming logic
void main()
{
int choice;
STACK stack;
char opt = 'Y'; // To continue the do loop in case
clrscr();
do
{
cout << "\n\t\t Main Menu";
cout << "\n\t1. Addition of Stack";
cout << "\n\t2. Deletion from Stack";
cout << "\n\t3. Exit from Menu";
cout << "\n\nEnter your choice from above ";
cin >> choice;
switch (choice)
{
case 1:
do
{
stack.PUSH();
cout << "\nDo you want to add more elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 2:
opt = 'Y'; // Initialize for the second loop
do
{
stack.POP();
cout << "\nDo you want to delete more elements <Y/N> ? ";
cin >> opt;
} while (toupper(opt) == 'Y');
break;
case 3:
exit(0);
}
}
while (choice != 4);
}