0% found this document useful (0 votes)
3 views

For DS Implementation Program

Write a program usimg implementation of stack and array

Uploaded by

prasadnerkar434
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

For DS Implementation Program

Write a program usimg implementation of stack and array

Uploaded by

prasadnerkar434
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Shri Vile Parle Kelavani Mandal's

INSTITUTE OF TECHNOLOGY
DHULE (M.S.)
DEPARMENT OF COMPUTER ENGINEERING
Remark
Subject : Data Structures Lab

Name : Prem Mangesh Mali Roll No. : 48

Class : SY. Comp. Engg. Batch : S2 Division: A


Signature
Expt. No. :01 Date : 05/08/24 to 12/08/24

Title : Write a program to implement stack using array.

#include<stdio.h>
int stk[100];
int n,top=-1;
int ch,data,i;
void push();
void pop();
void display();
int main(){
printf("Title : Write a program to implement stack using
arrays.\n");
printf("\nName :Prem Mali.\nRoll no :48\n\n");

printf("Enter the size of stack");


scanf("%d",&n);
do{
printf("\nSelect the operation to be performed on stack\
n1.Push\n2.Pop\n3.Display");
scanf("%d",&ch);
switch(ch){
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
default:printf("\nInvalid input");
}

printf("\nDo you want to continue press 1");


scanf("%d",&ch);
}while(ch==1);
}

void push(){
if(top==n)
printf("\n Stack Overflow");
else if(top==-1){
printf("\nEnter data:");
scanf("%d",&data);
top=0;
stk[top]=data;
top++;
}

else{
printf("\nEnter data:");
scanf("%d",&data);
stk[top]=data;
top++;
}

void pop(){
if(top==-1)
printf("\nStack Underflow");else{
data=stk[top];
top--;
printf("\nRemoved data is %d",data);
}
}
void display(){
printf("\nStack entries are");
for(i=top;i>-1;i--)
printf("\n%d",stk[i]);}
Output

Title : Write a program to implement stack


using arrays.

Name :Prem Mali.


Roll no :48

Enter the size of stack3

Select the operation to be performed on


stack
1.Push
2.Pop
3.Display1
Enter data:22

Do you want to continue press 11

Select the operation to be performed on


stack
1.Push
2.Pop
3.Display1

Enter data:33

Do you want to continue press 11

Select the operation to be performed on


stack
1.Push
2.Pop
3.Display1

Enter data:55

Do you want to continue press 11

Select the operation to be performed on


stack
1.Push
2.Pop
3.Display3

Stack entries are


0
55
33
22
Do you want to continue press 15

=== Code Execution Successful ===

You might also like