[go: up one dir, main page]

0% found this document useful (0 votes)
2 views2 pages

program 1

This document contains a C program that implements a stack data structure with basic operations: Push, Pop, and Show. The program allows users to interactively add elements to the stack, remove elements from it, and display the current elements in the stack. It includes error handling for overflow and underflow conditions.

Uploaded by

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

program 1

This document contains a C program that implements a stack data structure with basic operations: Push, Pop, and Show. The program allows users to interactively add elements to the stack, remove elements from it, and display the current elements in the stack. It includes error handling for overflow and underflow conditions.

Uploaded by

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

#include<stdio.

h>
#include<stdlib.h>
#define true 1
#define Size 20
int Top=-1, arr[Size];
void Push();
void Pop();
void show();
int main()
{
int choice;
while(true)
{
printf("\n1.Push the element\n2.Pop the element\n3.Show\n4.End");
printf("\n\nEnter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: Push();
break;
case 2: Pop();
break;
case 3: show();
break;
case 4: exit(0);
default: printf("\nInvalid choice!!");
}
}
}
void Push()
{
int item;
if(Top==Size-1)
{
printf("\nOverflow Condition");
}
else
{
printf("\nEnter element to be inserted to the stack:");
scanf("%d",&item);
Top=Top+1;
arr[Top]=item;
}
}
void Pop()
{
if(Top==-1)
{
printf("\nUnderflow Condition");
}
else
{
printf("\nPopped element: %d",arr[Top]);
Top=Top-1;
}
}
void show()
{
int i;
if(Top==-1)
{
printf("\nUnderflow Condition");
}
else
{
printf("\nElements present in the stack: \n");
for( i=Top;i>=0;--i)
printf("%d\n",arr[i]);
}
}

You might also like