forked from PankajJadwal/DS_B
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
110 lines (95 loc) · 1.49 KB
/
Copy pathstack.c
File metadata and controls
110 lines (95 loc) · 1.49 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// #include<stdio.h>
// void swap(int *x, int *y)
// {
// int temp=*x;
// *x=*y;
// *y=temp;
// }
// int main()
// {
// int a=2, b=3;
// printf("a-->%d b-->%d\n", a, b);
// swap(&a, &b);
// printf("a-->%d b-->%d\n", a, b);
// }
#include <stdio.h>
#include <stdlib.h>
#define MS 5
typedef struct stack
{
int top;
int arr[MS];
int size;
} stack;
void init(stack *s)
{
s->size = 0;
s->top = -1;
}
void push(stack *s, int x)
{
if (s->top == MS - 1)
{
printf(" isse jyada nahi ho payega!!\n");
return;
}
s->size++;
s->arr[++s->top] = x;
}
void display(stack *s)
{
for (int i = 0; i <= s->top; i++)
{
printf("%d ", s->arr[i]);
}
printf("\n");
}
void pop(stack *s)
{
if(s->top==-1)
{
printf("Undelflow\n");
return ;
}
--s->top;
}
int getSize(stack *s)
{
int size=s->top+1;
return size;
}
int getPeek(stack *s)
{
return s->arr[s->top];
}
int main()
{
stack s;
init(&s);
push(&s, 10);
display(&s);
push(&s, 20);
display(&s);
push(&s, 30);
display(&s);
printf("Size---> %d\n", getSize(&s));
push(&s, 40);
display(&s);
push(&s, 50);
printf("Top element---> %d\n", getPeek(&s));
display(&s);
push(&s, 60);
display(&s);
pop(&s);
display(&s);
pop(&s);
display(&s);
pop(&s);
display(&s);
pop(&s);
display(&s);
pop(&s);
display(&s);
pop(&s);
display(&s);
}