0% found this document useful (0 votes)
7 views6 pages

DSA Stack

Consists of notes on stacks and code in c

Uploaded by

vedant.spamz65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

DSA Stack

Consists of notes on stacks and code in c

Uploaded by

vedant.spamz65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PAGE NG

DATE

Assiqnment-3A
Afon
A menu dmves t program to inplement a
Stacr USig amray.

Theoyi
AStack a liear d t a Struhe wher
the elerments a e stored in an àrle ved

mane. The elem ents Stact are adde d


renore d only fon one end, hih is
Toe.
A S tac LIFO CLo h irst Owt
data Srh the elenent that ws (ased

i r s t one to bc
mnoned
StauC Supports Few basic op erUhons
be w
C19 Push
an l ement
PUsh operanons USed to iasert
in to the Stac The ne elemet is adde d a

of Stak
to embSt pSihon the
Conduhon heccecl Shat
The only
hehher the stace iS
ofinserions Possible

Let i a S tacc: LO2,30, 4o


new elm
Consi der pusho funuioo to iose Yt elemcn
pushc)
PUsh ( 30
in a SeqUnee
30
2) Pop
The Pop aper a o S USed
topmoSC et ement from hmc

Chee if TOp-0LL
the sra ck is

Represet aon

Afr caingpap

|i amroy seLLo, o, 3 J

30 30

3) Oispla

elemet

Tie Compie x S
Pop fun' ons ro
Compeny
Pusn opehon cI)
PAGE No.

DATE

ConcuSion

Forlouolng Oben ve we
USe
COncepts of
S21_100_Vedant Patil

Code:
#include<stdio.h>
#include<conio.h>

struct stack
{
int arr[10];
int top;
};
struct stack s1;
void display();
void pop();
void push();
void main()
{
int choice;
int n;
s1.top=-1;
do
{
printf("1.Push\n2.Pop\n3.Display\nEnter the choice to be performed: ");
scanf("%d",&choice);
switch(choice)
{
case 1://Perform Push
printf("Enter the number to be pushed: ");
scanf("%d",&n);
push(n);
break;
case 2://Perform Pop
pop();
break;
case 3://Display stack
display();
break;
default:
printf("Invalid choice");
break;
}
}while(choice<4);
}
void push(int n)
{
if(s1.top>=9)
{
printf("Stack is full\n");
S21_100_Vedant Patil

return;
}
s1.arr[++s1.top]=n;
}
void pop()
{
if(s1.top==-1)
{
printf("Stack at lowest level\n");
return;
}
printf("%d is the element popped\n",s1.arr[s1.top]);
s1.top--;
}
void display()
{
for(int i=s1.top;i>=0;i--)
{
printf("%d\n",s1.arr[i]);
}
if(s1.top==-1)
{
printf("Stack empty\n");
return;
}
}

Output:
1.Push
2.Pop
3.Display
Enter the choice to be performed: 1
Enter the number to be pushed: 12

1.Push
2.Pop
3.Display
Enter the choice to be performed: 1
Enter the number to be pushed: 13

1.Push
2.Pop
3.Display
Enter the choice to be performed: 1
Enter the number to be pushed: 14
S21_100_Vedant Patil

1.Push
2.Pop
3.Display
Enter the choice to be performed: 3
14
13
12

1.Push
2.Pop
3.Display
Enter the choice to be performed: 2
14 is the element popped

1.Push
2.Pop
3.Display
Enter the choice to be performed: 2
13 is the element popped

1.Push
2.Pop
3.Display
Enter the choice to be performed: 2
12 is the element popped

1.Push
2.Pop
3.Display
Enter the choice to be performed: 2
Stack at lowest level

1.Push
2.Pop
3.Display
Enter the choice to be performed: 3
Stack empty

You might also like