-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_implementation(linked_list).cpp
More file actions
64 lines (64 loc) · 1.29 KB
/
Stack_implementation(linked_list).cpp
File metadata and controls
64 lines (64 loc) · 1.29 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
#include<iostream>
using namespace std;
struct node{
int data ;
node* link;
};
void Push(node* &first ,int x){
node* p=new node;
p->data=x;
p->link=first;
first=p;
}
void Display(node* first){
node *t=first;
while(t!=NULL)
{
cout<<t->data<<" ";
t=t->link;
}
cout<<endl;
}
void pop(node* &first){
node* t=first;
first =first->link;
cout<<"element deleted: "<<t->data<<endl;
delete t;
}
int top(node* first){
return first->data;
}
int main()
{
node* first=NULL;
int n, choice , x;
cout<<"enter the size of the stack: ";
cin>>n;
do
{
cout<<"enter your choice\n"
<<"1.Push\n2.Display\n3.delete\n4.seek\n";
cin>>choice;
switch (choice)
{
case 1:
cout<<"enter the element you want to push: ";
cin>>x;
Push( first ,x );
break;
case 2:
cout<<"the elements are: \n";
Display(first);
break;
case 3:
pop(first);
break;
case 4:
cout<<"stack top is : "<<top(first)<<endl;
break;
default:
break;
}
} while (choice<=4);
return 0;
}