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

EXNO-16 15/09/10 Program To Explain Stack Program

The document contains a C program that demonstrates a stack implementation using an array. The program allows the user to push data onto the stack, pop data off the stack, and view the current data in the stack. It uses a top variable to track the top of the stack, and only allows pushes if the stack is not full. When data is popped, it is removed from the stack and displayed to the user.

Uploaded by

sathyadhoni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

EXNO-16 15/09/10 Program To Explain Stack Program

The document contains a C program that demonstrates a stack implementation using an array. The program allows the user to push data onto the stack, pop data off the stack, and view the current data in the stack. It uses a top variable to track the top of the stack, and only allows pushes if the stack is not full. When data is popped, it is removed from the stack and displayed to the user.

Uploaded by

sathyadhoni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXNO-16

PROGRAM TO EXPLAIN STACK


15/09/10

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int max=5;
int data[5],t,top=-1;
int i=0;
while(i<3)
{
printf("\n enter choice 1.push 2.pop 3.exit :");
scanf("%d",&i);
if (i==1)
{
printf("\n enter data to be pushed :");
scanf("%d",&t);
if (top==max-1)
{
printf("\n stack full");
}
else
{
top++;
data[top]=t;
}
}
if(i==2)
{
if(top==-1)
{
printf("\n stack empty");
}
else
{
t=data[top];
top--;
printf("\n poped data is =%d",t);
}

}
printf("\n\n data in stack \n\n");
for(t=0;t<=top;t++)
{
printf("\t%d",data[t]);
getch();
}
}
}

OUTPUT:

enter choice 1.push 2.pop 3.exit :2

stack empty

data in stack

enter choice 1.push 2.pop 3.exit :1

enter data to be pushed :33

data in stack

33
enter choice 1.push 2.pop 3.exit :1

enter data to be pushed :55

data in stack

33 55
enter choice 1.push 2.pop 3.exit :2

poped data is =55

data in stack

33
enter choice 1.push 2.pop 3.exit :3

data in stack

33

You might also like