3 Rdprogram
3 Rdprogram
h>
#include <stdlib.h>
#include <string.h>
#define MAX 5
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];
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");
}
}
}