The document contains code for implementing a stack data structure in C using an array with push, pop, and display functions. It includes a main menu driver program to test the stack implementation by allowing the user to push, pop, or display items and continues until the user chooses to exit. The stack uses a top pointer to track the current position and checks for overflow and underflow conditions.
Please help me implement this as a client of the Java library! static.docx
1. Please help me implement this as a client of the Java library!
static class MinMaxQueue {
void push(String val) {
}
String popMin() {
return "";
}
String popMax() {
return "";
}
int size() {
return 0;
}
}
/*
Solution
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
2. struct stack {
int s[size];
int top;
} st;
int stfull() {
if (st.top >= size - 1)
return 1;
else
return 0;
}
void push(int item) {
st.top++;
st.s[st.top] = item;
}
int stempty() {
if (st.top == -1)
return 1;
else
return 0;
}
int pop() {
int item;
item = st.s[st.top];
3. st.top--;
return (item);
}
void display() {
int i;
if (stempty())
printf(" Stack Is Empty!");
else {
for (i = st.top; i >= 0; i--)
printf(" %d", st.s[i]);
}
}
int main() {
int item, choice;
char ans;
st.top = -1;
printf(" tImplementation Of Stack");
do {
printf(" Main Menu");
printf(" 1.Push 2.Pop 3.Display 4.exit");
printf(" Enter Your Choice");
scanf("%d", &choice);
switch (choice) {
4. case 1:
printf(" Enter The item to be pushed");
scanf("%d", &item);
if (stfull())
printf(" Stack is Full!");
else
push(item);
break;
case 2:
if (stempty())
printf(" Empty stack!Underflow !!");
else {
item = pop();
printf(" The popped element is %d", item);
}
break;
case 3:
display();
break;
case 4:
exit(0);
}
printf(" Do You want To Continue?");