-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLinkedStack
More file actions
71 lines (68 loc) · 815 Bytes
/
LinkedStack
File metadata and controls
71 lines (68 loc) · 815 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
//https://www.facebook.com/srishti.agrawal.714/posts/162113345582696
//Subscribed by Srishti Agrawal
#include <iostream>
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<<"Stak is
Full\n";
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.Display();
cout<<stk.pop();
return 0;
}