FREE : [ Study Material ] NDA/SSB Preparation : Check Now!!! | Latest: HR Interview Questions:CHECK | Like Us :

Sunday, 28 April 2013

C PROGRAM TO IMPLEMENT STACK USING ARRAY | Stack USING ARRAY

0 comments
PROGRAM by Ashish

#include<stdio.h>
#include<conio.h>
#define MAX 10
int stack[MAX];
int top=-1;
void push(int num);
void pop();
void traverse();
void main()
{
int num,ch,p=0;
clrscr();
do
{
printf("Enter 1 to Print STACK\n");
printf("ENTER 2 to PUSH ITEM\n");
printf("ENTER 3 to POP ELEMENT\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nElements in Stack are:-\t");
traverse();
break;
}
case 2:
{
printf("\nEnter the Element to be pushed");
scanf("%d",&num);
push(num);
break;
}
case 3:
{
printf("\nGoing to Perform POP OPERATION");
pop();
break;
}
}
printf("\nENTER 1 to Continue");
scanf("%d",&p);
}while(p==1);
getch();
}
void traverse()
{
int i;
if(top==-1)
{
printf("\nStack is EMPTY");
}
else
{
for(i=top;i>=0;i--)
{
printf("\n%d",stack[i]);
}
}
}
void push(int num)
{
if(top==MAX)
{
printf("\nOVERFLOW");
}
else
{
top=top+1;
stack[top]=num;
printf("\n Element added");
}
}
void pop()
{
int item;
if(top==-1)
{
printf("\nUnder FLow");
}
else
{
item=stack[top];
top=top-1;
printf("\Element poped is%d",item);
}
}


Output:-

 

Results

get our extension

Like Us on FB

    Freshers Jobs

    Donate

    DMCA Protected

    You are Visitor Number

    Interview Questions

    SSB Questions

      Authors
    Tinku Singh
    Hitesh Dhanda

    MrNaukri.com - Get Sarkari Jobs, Results, Off Campus Placement Updates © 2012. All Rights Reserved | Back To Top |

    © 2013 A Product of IBC Network