You are on page 1of 4

WEEK-7

Name:CH.SANTHOSHINI

R.NO:21R25A0421

Problem statement:
Write a C Program to Implement a Stack using Array and

perform

1)Insertcharacterssintothestack

2)Deletethreeelementsfromstack

3)Displaythestackinreverseorder

Forexample,if stackelementsare ABCDEF

thenthefunctionshouldprintCBAafterremovingF,E,D

#include<stdio.h>

#include<stdlib.h>

#definesize10

voidpush(char);

voidpop();

voidreverse_order();

voiddisplay();

intstack[size],top=-1;

voidmain()

intchoice;

charvalue;

while(1)

printf("\n1.push,2.pop,3.reverseorder,4.display,5.3exit");
printf("\nenteryourchoice");

scanf("%d",&choice);

switch(choice)

case1:printf("\nentervaluetoinsert");

scanf("%c",&value);

push(value);

break;

case2:pop();

break;

case3:reverse_order();
break;

case4:display();

break;

case5:exit(0);

default:printf("\ninvalidchoice"); }

voidpush(charvalue)

if(top==size-1)

printf("\nstackisfull");

else

{
top++;

stack[top]=value;

printf("\ninsertingsuccessful"); }

voidpop()

if(top==-1)

printf("\nstackisempty");
}

else

printf("\ndeleted %c",stack[top]);

top--;

voidreverse_order()

inti;

if(top==-1)

printf("\nstackisempty");

else

for(i=0;i<=top;i++)
{

printf("%c->",stack[i]);

voiddisplay()

inti;
if(top==-1)

printf("\nstackisempty");

else

for(i=top;i>=0;i--)

printf("%c->",stack[i]);

OUTPUT:

You might also like