forked from Shivam4747/Hacktoberfest2021-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackUsingLinkedList.cpp
More file actions
85 lines (83 loc) · 1.2 KB
/
Copy pathstackUsingLinkedList.cpp
File metadata and controls
85 lines (83 loc) · 1.2 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
#include<iostream>
using namespace std;
class node{
public:
int data;
node* next;
node(int value){
data=value;
next=NULL;
}
};
class stack{
public:
node* top;
node* bottom;
int length = 0;
stack(){
top=NULL;
bottom=NULL;
length=0;
}
void push(node* &head,int value){
node* temp=head;
node* n = new node(value);
if(length==0){
head=n;
top=n;
}else{
top->next=n;
top=n;
}
length++;
}
void display(node* head){
if(length==0){
cout<<"NOTHING TO DISPLAY";
}else{
while(head!=NULL){
cout<<head->data<<"-->";
head=head->next;
}
cout<<"NULL";
}
}
void peek(){
cout<<"\nTop Data: "<<top->data;
}
void DELETE(node* &head){
if(length==0){
cout<<"Stack is UNDERFLOWN";
}
else{
node* temp = top;
node* prev=NULL;
while(temp->next!=NULL){
prev=temp;
temp=temp->next;
}
prev->next=NULL;
top=prev;
delete(temp);
}
}
};
int main()
{
stack* s = new stack;
node* head=NULL;
s->push(head,2);
s->push(head,3);
s->push(head,12);
s->push(head,13);
s->push(head,18);
s->display(head);
cout<<"\n";
// s->DELETE(head);
// s->display(head);
// s->DELETE(head);
// s->display(head);
s->peek();
// s->peek();
return 0;
}