Middel Element
Middel Element
#include <stdio.h>
#include <conio.h>
int stack[MAX];
intmiddleIndex;
inttempStack[MAX];
inttempTop,i;
printf("Stack overflow\n");
} else {
stack[++top] = value;
int pop() {
if (top == -1) {
printf("Stack underflow\n");
return -1;
} else {
return stack[top--];
voiddeleteMiddle() {
if (top == -1) {
printf("Stack is empty\n");
return;
//tempStack[MAX];
tempTop = -1;
// Remove elements above the middle element and store them in a temporary stack
tempStack[++tempTop] = pop();
// Pop the middle element (do not store it, effectively deleting it)
pop();
// Push back the elements from the temporary stack to the original stack
push(tempStack[tempTop--]);
void display() {
if (top == -1) {
printf("Stack is empty\n");
return;
printf("\n");
void main() {
push(1);
push(2);
push(3);
push(4);
push(5);
printf("Original Stack:\n");
display();
deleteMiddle();
display();
getch();
}
Output=