-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackusingLL.cpp
More file actions
64 lines (63 loc) · 1.16 KB
/
stackusingLL.cpp
File metadata and controls
64 lines (63 loc) · 1.16 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;
class node{
public:
int data;
node* next;
node(int val){
data=val;
next=NULL;
}
};
class stack{
node* top;
public:
stack(){top=NULL;}
void push(int val)
{
node* t = new node(val);
t->next = top;
top=t;
cout<<val<<"pushed success\n";
}
void pop(){
if(top==NULL){
cout<<"stack is empty\n";
return;
}
cout<<top->data<<"pop\n";
node* temp =top;
top=top->next;
delete temp;
}
void front(){
if (top == NULL) {
cout << "Stack is empty\n";
} else {
cout << "Top element: " << top->data << "\n";
}
}
void display(){
if(top==NULL){
cout<<"stack is empty\n";
return;
}
node* temp = top;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
};
int main() {
stack s;
s.push(10);
s.push(20);
s.push(30);
s.display();
s.front();
s.pop();
s.display();
return 0;
}