Saturday, July 6, 2019

Program and Algorithm for POP ,PEEP and PUSH operation on stack (array) in C Data Structures


For many other Assembly Language  Programs related to microprocessor 8086, c++ , datastructures  visit our  BLOG 


Algorithm And Program: -

PUSH :

1.if top==MAX-1 then  print stack is full (overflow)
2.else accept data items from the user
3.set top=top+1
4.stack[top] = item
5.stop

POP:  

1.if top==-1 then print stack is empty (underflow)
2.else   set item= stack[top]
3.set top=top-1
4.stop

Program:

#include<stdio.h>
#include<conio.h>
#define maxsize 10
//---functions--
void pop();
void peep();
void push();
void display();
//------------------
void main()
{
int stack[maxsize] ;
int  top=-1 , i, n ;
clrscr();
printf(“****   OPERATIONS **** \n\n”);
printf(“1.pop  \n2.peep \n3.push \n4.display\n\n\n”);
printf(“enter choice : =  ”);
scanf(“%d”,&n);
do
{
switch(n)
{
case 1 : pop();
break;
case 2: peep();
break;
case 3:push();
break;
case 4: display();
case 5: break;
default:printf(“invalid entry”);
}
}while(c!=5);
getch();
}
void pop()
{
int y;
if(top==-1)
{
printf(“stack is underflow”);
}
else
{
y= stack[top];
top=top-1;
printf(“element deleted ”);
}
}

void peep();
{
if(top== 1)
printf(“stack is full underflow”);
else
printf(“topmost data = %d ”,stack[top]);
}

void display()
{
if(top== 1)
printf(“stack is full underflow”);
else
for(int q=0;q<maxsize-1;q++)
printf(“\n%d”,stack[q]);
}
void push()
{
int x;
if(top==(maxsize-1))
{
printf(“stack is full (overflow)”);
}
else
{
printf(“enter data”);
for(i=0;i<n;i++)
scanf(“%d”,&x);
top=top+1;
stack[top]=x;
}
}


Programs

For many other Assembly Language  Programs related to microprocessor 8086 visit our  BLOG 

There are programs of largest ,smallest ,division ,multiplication,odd/even,block operation ,string operations ,etc


No comments:

Post a Comment