0% found this document useful (0 votes)
10 views3 pages

Lab1 Implementation of Stack Using Array

This document contains a C program that implements a stack data structure using an array. It includes functions for pushing elements onto the stack, popping elements from the stack, and displaying the current elements in the stack. The program runs in a loop, allowing the user to choose operations until they decide to exit.

Uploaded by

bhattaraienjal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Lab1 Implementation of Stack Using Array

This document contains a C program that implements a stack data structure using an array. It includes functions for pushing elements onto the stack, popping elements from the stack, and displaying the current elements in the stack. The program runs in a loop, allowing the user to choose operations until they decide to exit.

Uploaded by

bhattaraienjal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// Implementation of Stack using Array

#include<stdio.h>
#include<conio.h>
#define max 5
int stack[max];
int top=-1;
// function for push the element into stack
void push()
{
int element ;
if(top==max-1)
printf("Overflow");
else
{
printf("Enter a number ");
scanf("%d",&element);
top=top+1;
stack[top]=element;
}
}
// function for pop the element from the stack
void pop()
{
int element;
if(top==-1)
printf("Underflow condition");
else
{
element=stack[top];
printf("pop element is %d",element);
top=top-1;
}
}
// function for display the element of the stack
void display()
{
int element,i;
if(top==-1)
printf("Underflow condition");
else
{
for(i=top;i>=0;i--)
{
printf("%d ",stack[i]);
}
}
}
//Driver function
void main()
{
int ch;
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
printf("[Link]\n");
while(1)
{
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default:
printf("Worng key");
}
}
}

You might also like