CDS ASSIGNMENT 3 Ans

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ASSIGNMENT-3

Implement All Operation in Stack


INPUT
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
int top=-1;
int stack[10];
void push()
{
if(top==9)
{printf("stack is full");}
else
{int x;
top++;
printf("\nenter the %dth element",top+1);
scanf("%d",&x);
stack[top]=x;
}}
void pop()
{
if(top==-1)
{printf("\nstack is empty");}
else
{
printf("\n%dth element is deleted",top+1);
top--;
}}
void display()
{
if(top==-1)
{printf("\nstack is empty");}
else
{int i;
for(i=0;i<=top;i++)
{printf("\n%dth element is
%d",i+1,stack[i]);}
}
}
void main()
{
int choice;
clrscr();
do{
printf("\nEnter operation choice from
following:\n1:Insertion\n2:Deletion\
n3:Display\n4:exit\n");
scanf("%d",&choice);
switch(choice){
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:exit(1);
default:
printf("invalid input");
}}while(choice!=-1);
getch();}
OUTPUT
INSERTION
DISPLAY

DELETION

You might also like