CREATE STACK USING ARRAY

816

bca third semester

Create stack using Array

program data structure

This Implementation is correct you can use our program

if you like please share with your BCA Friend.

 

#include<stdio.h>
#include<conio.h>
#define max 5
void push();
int pop();
void display();

int stack[max];
int top=-1;
void main()
{
int n,item,ch,ele;
clrscr();
do
{
clrscr();
printf("1. Push Operation \n2. Pop Operation \n3. Display\n4. Exit\n\nEnter Your Choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
clrscr();
if(top==max-1)
{
printf("Stack Overflow !!!!!!!!!");
getch();
}
else
{
printf("\nEnter Any Number : ");
scanf("%d",&item);
push(item);
break;
}

case 2:

if(top==-1)
printf("Stack Underflow !!!!!!");
else
ele = pop();
printf("Deletion Element is = %d",ele);
getch();
break;

case 3:
display();
break;
}
}while(ch != 4);
// getch();
}

/////////////////////////
void push(int number)
{
top++;
stack[top] = number;
}

int pop()
{
int num;
if(top == -1)
printf("Stack Underflow !!!!!!");
else
num = stack[top];
top--;
return num;
}

void display()
{
int i;
clrscr();
if(top == -1)
printf("Stack Undrflow !!!!!!!!");
else
{
printf("Stack Elements - \n");
for(i=top;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
getch();
}

 

 

OUTPUT
1. Push Operation
2. Pop Operation 
3. Display
4. Exit
Enter Your Choice : 1
Enter any Number : 10

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 1
Enter any Number : 20

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 1
Enter any Number : 30

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 1
Enter any Number : 40

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 1
STACK OVERFLOW!!!!!!!!!

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 3
Stack Element -
50
40
30
20
10


1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
Deletion Element is = 50

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
Deletion Element is = 40

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
Deletion Element is = 30
1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
Deletion Element is = 20
1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
Deletion Element is = 10

1. Push Operation 
2. Pop Operation 
3. Display
4. Exit
 
Enter Your Choice : 2
STACK UNDERFLOW !!!!!!!!!

 

 

BCA 3rd sem Third semester crate stack using array data structure

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here