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

3 Rdprogram

hvhv

Uploaded by

manojsj861338
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)
17 views2 pages

3 Rdprogram

hvhv

Uploaded by

manojsj861338
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
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>

#define MAX 5

int Stack[MAX], top = -1;

void push() {
int ele;
if (top < MAX - 1) {
printf("Enter the value to be inserted into the stack: ");
scanf("%d", &ele);
Stack[++top] = ele;
} else {
printf("Stack Overflow! Cannot insert more elements.\n");
}
}

void pop() {
if (top != -1) {
printf("The element deleted from the stack is: %d\n", Stack[top--]); //
Decrement top and remove the element
} else {
printf("Stack Underflow! The stack is empty.\n");
}
}

void Palindrome() {
int i = 0, len = top + 1, flag = 0;
int stack1[MAX];

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


stack1[i] = Stack[i];
}

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


if (stack1[i] != Stack[len - 1 - i]) {
flag = 1;
break;
}
}

if (flag == 0)
printf("The stack is a Palindrome.\n");
else
printf("The stack is not a Palindrome.\n");
}

void display() {
int i;
if (top == -1) {
printf("Stack is empty.\n");
} else {
printf("\nElements in the stack are:\n");
for (i = 0; i <= top; i++) {
printf("%d\n", Stack[i]);
}
}
}

int main() {
int choice;
while (1) {
printf("\n\n\n\t1. Push\n\t2. Pop\n\t3. Check Palindrome\n\t4.
Display\n\t5. Exit\n");
printf("\nEnter your choice: ");
scanf("%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! Please try again.\n");
}
}
}

You might also like