-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.cpp
62 lines (59 loc) · 908 Bytes
/
Stack.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
#include<iostream>
using namespace std;
int top1;
struct node
{
int data;
struct node *next;
};
struct node* top;
void push(int d){
struct node* temp = new node();
temp->data=d;
temp->next=top;
top=temp;
}
void pop(){
struct node* temp;
if(top==NULL)
cout<<"\nStack is empty";
else{
temp=top;
top=temp->next;
temp->next=NULL;
delete(temp);
}
}
void display(){
struct node* temp;
if(top==NULL)
cout<<"\nStack is empty";
else
{
temp=top;
while (temp!=NULL)
{
cout<<temp->data<<"\t";
temp=temp->next;
}
}
}
void isempty()
{
if (top1==-1){
cout<<"Stack is Empty"<<endl;
}
else{
cout<<"Stack is not Empty"<<endl;
}
}
int main(){
push(10);
push(20);
push(30);
push(40);
isfull();
pop();
isempty();
display();
}