‘Anew version of the above code which is shorter for real time implementation of
EXIT POINT
stack data structure in C language
1
2
3
4
5
6
7
a
9
1
Hincludecstdio.h>
Hincludecstdlib.h>
int n, top = «1, *stack;
void push(int x){
s¢(tops=n) return;
stack[++top}=x;
int
int peek()(
-1) return -15
return stack[top];
void display(){
for(int dstop ; is-1 ; i++) print#("Xé ",stack[i]);
print €("\n\n")5
Ant madn(){
ps amu pcarrningsconporanscrogrnslzsrokmorsr-staksergray ie
Page Replacement,
Programs in C
C Program to
Implement Doubly
Linked List|
Operations
Finding GCD and
LOM of Given
Numbers using C
C Program to Find,
‘Area and
Circumference of a
circle»
: printf(*Pushing elements into the stack\n1\n2\n3\n\n");
36 ha
> pean;
2 busn()s
push(3)5
“ rt #(“Displ Jlenents of the stack
2 print ("Displaying elenents of the stack -\n");
42 icp
: ssplay()s
a
printf("The top of the stack = %é\n\n",peek());
4s
46
. printf ("Pop the top of the stack = Xd\n\n",pop())s
8
. printf(*Pop the tos of the stack = Xd\n\n",pop())
50
printf(*Displaying elenents of the stack -\n");
st
52 aisptyos
S ssplay()3
2 turn 0)
sf, reeum es
ourpur;
Initializing the stack with size 10
Pushing elements into the stack
1
2
3
Displaying elenents of the stack -
327
The top of the stack = 3
Pop the top of the stack = 3
Pop the top of the stack
Displaying elenents of the stack -
1
‘The shorter version of the code was contributed by Nizam.
‘Queue follows the insert and delete operations through First in First Out approach,
check the below program for Queue operations.
Implementation of Queue using Array in C
Privacy Policy Cookie Policy
vt
© [Link] 2024
ps amu pcarringconporansc ogra zsrokmorsr-