Untitled
unknown
plain_text
2 years ago
1.3 kB
6
Indexable
#include <stdio.h>
#include <stdlib.h>
#define SIZE = 10
int is_empty();
int is_full();
void push();
void pop();
void display();
// push pop display is_empty is_full
int main()
{
int stack[SIZE], choice, top=-1, item;
printf("Options for stack operations :\n");
printf("1. Push\n2. Pop\n3. peek\n4. Exit\n");
printf("Please choose an option : ");
scanf("%d", &choice);
do{
switch(choice){
case 1:
push(stack)
break;
case 2:
pop();
break;
case 3:
display();
break;
}
}
return 0;
}
int is_full(){
if(top==SIZE-1){
return 1;
} else {
return 0;
}
}
int is_empty(){
if(top==-1){
return 1
} else {
}
}
void push(int a[]){
if(is_full()==0)
{
printf("\nEnter the element to push:");
scanf("%d", &item);
top = top + 1;
a[top] = item;
}
else{
printf("\nError: Overflow! Stack is full! Couldn't perform PUSH operation.");
}
}
void pop(){
if (is_empty()==-1){
printf("Sorry the stack is underflow!")
}
stack[top]
}
Editor is loading...
Leave a Comment