0% found this document useful (0 votes)
52 views4 pages

Program 3

This document contains a C program that implements a stack data structure with operations such as push, pop, display, and palindrome check. The stack has a maximum size of 5 and allows users to interact through a menu-driven interface. The program handles stack overflow and underflow conditions and checks if the elements in the stack form a palindrome.
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)
52 views4 pages

Program 3

This document contains a C program that implements a stack data structure with operations such as push, pop, display, and palindrome check. The stack has a maximum size of 5 and allows users to interact through a menu-driven interface. The program handles stack overflow and underflow conditions and checks if the elements in the stack form a palindrome.
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

#include<stdlib.

h>

#include<stdio.h>

#include<string.h>

#define max_size 5

int stack[max_size], top = -1;

int a[10], n;

void push() //Inserting element into the stack

int item;

if (top == (max_size - 1))

printf("\nStack Overflow:");

else

printf("Enter the element to be inserted:\t");

scanf("%d", &item);

top = top + 1;

stack[top] = item;

void pop() //deleting an element from the stack

int item;

if (top == -1)

printf("Stack Underflow:");

else

item = stack[top];

top = top - 1;

printf("\nThe poped element: %d\t", item);


}

void display() //Display function

int i;

if (top == -1)

printf("Stack Empty\n");

else

printf("Elements Are:\n");

for (i = top; i >= 0; i--)

printf("%d\n", stack[i]);

int palindrome() //Palindrome

int k, len = top + 1, rev[max_size], i, j = 0;

if (top == -1)

printf("Stack Empty\n");

else

printf("Array elements are : \n"); //displaying array elements

for (i = top; i >= 0; i--)

printf("%d\t", stack[i]);

for (k = len - 1; k >= 0; k--, j++) //performing reverse operation

rev[k] = stack[j];

printf("\n reverse array : \n");

for (k = 0; k<len; k++)

printf("%d\t", rev[k]);
for (i = 0; i<len; i++) //check for palindrome

if (stack[i] != rev[i])

break;

if (i == len)

printf("\n It is palindrome number\n");

else

printf("\n It is not a palindrome number\n");

return 0;

int main()

int choice;

while (1)

printf("\n\n--------STACK OPERATIONS-----------\n");

printf("[Link]\n");

printf("[Link]\n");

printf("[Link]\n");

printf("[Link]\n");

printf("[Link]\n");

printf("-----------------------");

printf("\nEnter your choice:\t");

scanf_s("%d", &choice);

switch (choice)

case 1:push();

break;
case 2:pop();

break;

case 3:palindrome();

break;

case 4:display();

break;

case 5:exit(0);

default:printf("\nInvalid choice:\n");

You might also like