-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSTACK_linkedl.cpp
72 lines (71 loc) · 971 Bytes
/
STACK_linkedl.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
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct node
{
int data;
node *ptr;
};
void push(node *&top)
{
node *t;
t = new node;
cout<<"enter number: ";
cin>>t->data;
t->ptr = top;
top = t;
}
void pop(node *&top)
{
cout<<"Deleted Element is: "<<top->data;
node *t;
t = top;
top = top->ptr;
delete t;
}
int isempty(node *top)
{
if(top == NULL)
return 1;
else
return 0;
}
void display( node *top)
{
node *t;
t = top;
while(t != NULL)
{
cout<<t->data<<'\n';
t = t->ptr;
}
}
void main()
{
node *top;
top = NULL;
int opt;
start:
clrscr();
cout<<" 1. PUSH \n";
cout<<" 2. POP \n";
cout<<" 3. DISPLAY \n";
cout<<" 4. EXIT \n";
cin>>opt;
switch(opt)
{
case 1: push(top);
break;
case 2: if(isempty(top) == 1)
cout<<"U/F";
else
pop(top);
getch();
break;
case 3: display(top);
getch();
break;
}
if(opt < 4 )
goto start;
}