Monday, June 29, 2015

Static Implementation of Stack

Posted By: BackBenchers World - Monday, June 29, 2015

Share

& Comment

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5

int stack[MAX], top;

void display()
{
int i;

printf("The Elements in Stack are:\n");
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}

void push()
{
char no;

if(top==MAX-1) printf("Stack Overflow");

else
{
top=top+1;

printf("Enter a Number: ");
scanf("%d",&no);

stack[top]=no;
display();
}
}

void pop()
{
if(top==-1) printf("Stack Underflow");

else
{
top--;
display();
}
}

void main()
{
clrscr();
char ch=1;
top=-1;
char choice;
printf("Working with Data Structure\n\n");
printf("Menu\n\n1. Push\n2. Pop\n");
printf("0. Exit");

while(ch)
{
printf("\n\nEnter your choice: \n");
choice=getch();

switch(choice)
{
case '1': push();
break;

case '2': pop();
break;

case '0': return;

default: printf("Wrong choice");
}
}
}

About BackBenchers World

Techism is an online Publication that complies Bizarre, Odd, Strange, Out of box facts about the stuff going around in the world which you may find hard to believe and understand. The Main Purpose of this site is to bring reality with a taste of entertainment

0 comments:

Post a Comment

Copyright © 2013 TechDotHunter™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.