-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_using_linkedlist.cpp
More file actions
91 lines (64 loc) · 935 Bytes
/
stack_using_linkedlist.cpp
File metadata and controls
91 lines (64 loc) · 935 Bytes
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
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
class Stack
{
private:
Node *top;
public:
Stack() {top=NULL;}
void push(int x);
int pop();
void Display();
};
void Stack::push(int x)
{
Node *t = new Node;
if (t==NULL)
{
cout<<"stack is full";
}
else
{
t->data=x;
t->next=top;
top=t;
}
}
int Stack::pop()
{ int x=-1;
if(top==NULL)
cout<<"stack is empty\n";
else{
x=top->data;
Node *t=top;
top=top->next;
delete t;
}
return x;
}
void Stack::Display(){
Node *p=top;
while (p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
int main()
{
Stack stk;
stk.push(10);
stk.push(20);
stk.push(30);
stk.push(40);
stk.Display();
cout<<stk.pop();
return 0;
}