-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.cpp
52 lines (50 loc) · 892 Bytes
/
practice.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
#include<iostream>
using namespace std;
struct stack{
int size;
int top;
int * arr;
};
int isEmpty(struct stack * ptr){
if (ptr->top==-1){
return 1;
}
else{
return 0;
}
}
int isFull(struct stack * ptr){
if(ptr->top == ptr->size-1){
return 1;
}
else{
return 0;
}
}
int push(struct stack * ptr, int val){
if(isFull(ptr)){
cout<<"Overflow"<<endl;
}
else{
ptr->top++;
ptr->arr[ptr->top] = val;
}
}
int main(){
struct stack *st = (struct stack *)malloc(sizeof(struct stack));
st->size=5;
st->top=-1;
st->arr = (int *)malloc(st->size * sizeof(int));
push(st, 10);
push(st, 10);
push(st, 10);
push(st, 10);
push(st, 10);
push(st, 10);
if(isEmpty(st)){
cout<<"Empty"<<endl;
}
else{
cout<<"Not Empty"<<endl;
}
}