forked from auralshin/competetive-code-hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.c
More file actions
75 lines (64 loc) · 1.14 KB
/
Copy pathstack.c
File metadata and controls
75 lines (64 loc) · 1.14 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
65
66
67
68
69
70
71
72
73
74
75
/*
The below program shows the full implementation of a stack data structure in C using arrays
*/
#include<stdio.h>
#include<stdlib.h>
int isEmpty();
int isFull();
void push();
int pop();
void displayStack();
struct Stack{
int top;
int totalSize;
int *ptr;
};
void push(struct Stack * s,int n){
if(isFull(s)==0){
s->top+=1;
s->ptr[s->top]=n;
}
else{
printf("Stack overflow\n");
}
}
int pop(struct Stack *s){
if(isEmpty(s)==0){
int n=s->ptr[s->top];
s->top-=1;
return n;
}
else{
printf("Stack underflow\n");
}
}
void displayStack(struct Stack *s){
for (int i = 0; i<=s->top; i++){
printf("%d\n",s->ptr[i]);
}
}
int isFull(struct Stack *s){
if(s->top==(s->totalSize)-1){
return 1;
}
else{
return 0;
}
}
int isEmpty(struct Stack *s){
if(s->top==-1){
return 1;
}
else{
return 0;
}
}
int main(){
struct Stack *s=(struct Stack *)malloc(sizeof(struct Stack));
s->top=-1;
s->totalSize=80;
s->ptr=(int *)malloc(s->totalSize*sizeof(int));
pop(s);
push(s,2);
displayStack(s);
}