-
Notifications
You must be signed in to change notification settings - Fork 4
/
stackll.cpp
72 lines (67 loc) · 1.02 KB
/
stackll.cpp
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
#include<iostream>
using namespace std;
struct node{
int data;
struct node *prev;
};
struct node *top=NULL;
//function to push any element//
void push (int element)
{
struct node *newnode=new node;
newnode->data=element;
newnode->prev=top;
cout<<"\nyour element "<<element<<" is inserted\n";
}
//function to pop element//
void pop (void)
{
struct node *temp=top;
if(top==NULL)
{
cout<<"Stack Empty";
}
else
{
top=top->prev;
delete(temp);
}
cout<<"Your element is popped";
}
//function to display stack elements//
void display(void)
{
struct node *temp=top;
while(temp != NULL)
{
cout<<temp->data;
temp=temp->prev;
}
cout<<endl;
}
//function to peep from stack//
void peep (void)
{
if(top==NULL)
{
cout<<"Stack is empty:";
return;
}
else
{
cout<<"Element on the top is :"<<top->data<<endl;
}
}
//main function//
int main ()
{
push(10);
push(20);
push(30);
push(40);
display();
pop();
display();
peep();
display();
}