20
20
h>
#include <stdlib.h>
struct Node {
int data;
};
int isEmpty() {
void display() {
if (isEmpty()) {
printf("Stack is empty.\n");
return;
temp = temp->next;
printf("\n");
newNode->next = top;
top = newNode;
int pop() {
if (isEmpty()) {
printf("Stack underflow.\n");
return -1;
top = top->next;
free(temp);
return val;
void topElement() {
if (isEmpty()) {
printf("Stack is empty.\n");
return;
void menu() {
while (1) {
printf("\nMenu:\n");
printf("1. Check if stack is empty\n");
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
break;
case 2:
display();
break;
case 3:
topElement();
break;
case 4:
scanf("%d", &val);
push(val);
break;
case 5:
val = pop();
break;
case 6:
exit(0);
default:
printf("Invalid choice.\n");
int main() {
menu();
return 0;