forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linear Stack
113 lines (93 loc) · 1.3 KB
/
Linear Stack
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
111
112
113
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
int stack[SIZE];
int top= -1;
void push();
void pop();
void size();
void display();
void top_val();
int Isfull();
int Isempty();
void main()
{ int ch;
while(1)
{ printf("\n Operations on static Stack : \n ");
printf("1. Push \n 2. Pop \n 3. Size \n 4. Display \n 5.Top_Value \n 6.Exit");
scanf("%d",&ch);
switch(ch)
{case 1: push();
break;
case 2:pop();
break;
case 3:size();
break;
case 4:display();
break;
case 5: top_val();
break;
case 6:exit(0);
break;
default: printf("Invalid choice\n");
}
}
}
void push()
{int ele;
printf("\n Enter Element :");
scanf("%d",&ele);
if(Isfull())
{
printf("Stack Overflow");
}
else
{ top++;
stack[top]=ele;
}
}
int Isfull()
{ if(top==SIZE-1)
{
return(1);
}
else
return(0);
}
void pop()
{int a;
if(Isempty())
{
printf("Stack Underflow");
}
else
{ a=stack[top];
top--;
printf("Popped Value : %d\n",a);
}
}
int Isempty()
{ if(top==-1)
{
return(1);
}
else
return(0);
}
void size()
{ int count;
count=top+1;
printf("Size of Stack:%d \n",count);
}
void display()
{ int i=0;
printf("Elements in Stack:");
for(i=0;i<=top;i++)
{
printf("%d ",stack[i]);
}
}
void top_val()
{
printf("Top Element : %d \n",stack[top]);
}