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

C Stack Operations and Palindrome Check

This document contains a C program that implements a stack with operations such as push, pop, palindrome check, stack status check, and display. It uses arrays to manage stack elements and includes user interaction through a menu-driven interface. The program allows users to perform various stack operations until they choose to exit.

Uploaded by

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

C Stack Operations and Palindrome Check

This document contains a C program that implements a stack with operations such as push, pop, palindrome check, stack status check, and display. It uses arrays to manage stack elements and includes user interaction through a menu-driven interface. The program allows users to perform various stack operations until they choose to exit.

Uploaded by

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

#include<stdio.

h>

#include<stdlib.h>

#include<string.h>

#define MAX 5

int stack[MAX],top=-1;

char stack1[MAX],top1=-1;

void push()

int ele;

if(top<MAX-1)

printf("enter the value to be inserted into the stack:\n");

scanf("%d",&ele);

stack[++top]=ele;

else

printf("\n stack is full\n");

return;

void pop()

if(top!=-1)

printf("\n the element deleted from the stack is:%d\n",stack[top--]);

else

printf("\n stack is empty\n");

return;

void palindrome()

{
int i,count=0,len;

char str[100];

printf("\n entertring to check whether it is palindrome or not:");

scanf("%s",str);

len=strlen(str);

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

stack1[++top1]=str[i];

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

if(str[i]==stack1[top1--])

count++;

if(count==len)

printf("\n %s is a palindrome string\n",str);

else

printf("\n %s is not a palindrome string\n",str);

return;

void check()

if(top>=MAX-1)

printf("stack is overflow\n");

else if(top==-1)

printf("stack is underflow\n");

else

printf("stack operation can be performed\n");

void display()

{
int i;

if(top==-1)

printf("\n stack is empty\n");

else

printf("\n elements in the stack are\n");

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

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

return;

void main()

int choice;

while(1)

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

printf("\n 1:push\t2:pop\t3:palindrome\t4:check\t5:display\t6:exit\n");

printf("\n enter your choice[1/2/3/4/5/6]:");

scanf("%d",&choice);

switch(choice)

case 1: push();break;

case 2: pop();break;

case 3: palindrome();break;

case 4: check();break;

case 5: display();break;

case 6: exit(0);

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


}

return;

You might also like