-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstackpointer.cpp
More file actions
86 lines (81 loc) · 1.56 KB
/
stackpointer.cpp
File metadata and controls
86 lines (81 loc) · 1.56 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
#include<iostream>
#include<vector>
using namespace std;
struct node{
int data;
node* next;
node(int x){
data=x;
next=NULL;
}
};
node* push(node* head,int x){
node* temp=new node(x);
if(head==NULL){
return temp;
}
else {
temp->next=head;
return temp;
}
}
node* pop(node* head){
if(head==NULL){
cout<<"UNDERFLOW";
return head;
}
node* temp=head;
head=head->next;
delete(temp);
return head;
}
void show(node* head){
node*temp= head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
return;
}
int main(){
node* head=NULL;
while(true){
cout<<"Enter 1 for insertion "<<endl;
cout<<"Enter 2 for deletion "<<endl;
cout<<"Enter 3 for top "<<endl;
cout<<"Enter 4 for show "<<endl;
cout<<"Enter 5 for exit "<<endl;
int a;
cin>>a;
if(a==1){
cout<<"Enter the element ";
int x;
cin>>x;
head=push(head,x);
cout<<endl;
}
else if(a==2){
head=pop(head);
cout<<endl;
}
else if(a==3){
if(head==NULL){
cout<<"NULL";
}
else
cout<<head->data<<endl;
}
else if(a==4){
show(head);
}
else if(a==5){
break;
}
else{
cout<<"entered wrong!! retry"<<endl;
cout<<endl;
}
}
return 0;
}