Share the code
//
// Created by hassa on 01/10/2022.
//
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define size 5
int stack[size];
int top=-1;
int data;
void push();
void pop();
void peek();
void display();
void push(){
printf("Enter the data that you want ");
scanf("%d",&data);
if(top==size-1)
printf("the stack has been overflow");
else{
top++;
stack[top]=size; // pay attention
// until be full // it needs to understand much better
}
}
void pop(){
int item;
if(top==-1)
printf("underflow");
else{
item= stack[top]; // pay attention // and if you dont want to write the pop item there is no need to write this line
top--;
printf("%d",item);
}
}
void peek(){ // top
if(top == -1)
printf("the stack is empty");
else
printf("the top is %d",stack[top]);
}
void display(){
for (int i=top ; i>=0 ; i--) {
printf("the value of the stack << is %d",stack[i]);
}
}
int main() {
int choice=1;
int d;
do {
printf("1- to push it\n");
printf("2- to pup them\n");
printf("3- to show the last top\n");
printf("4- to display them \n");
printf(" pressed 0 to get out \n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: push();
// printf("\nEnter A value:");
// scanf("%d",&d);
break;
case 2: pop();
break;
case 3: peek();
break;
case 4: display();
break;
default:
printf("wrong choice\n");
}
} while (choice !=0);// it will get out if we pressed 0
getch();
}