Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
0
Indexable
Never
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX_SIZE 5
int stack[MAX_SIZE];
int top =-1;
void push(int item){
	if(top==MAX_SIZE-1){
		printf("STACK IS OVERFLOW \n");
	}
	else {
		top++;
		stack[top]=item;
	}
}
void pop(){
	if(top==-1){
		printf("STACK IS UNDERFLOW \n");
	}
	else{
		int item;
		item=stack[top];
		top--;
		printf("Deleted item is %d",item);
	}
}
void peep(){
	if(top==-1){
		printf("STACK IS UNDERFLOW \n");
	}
	else {
		int i;
		for(i=top; i>=0; i--){
			printf("<-%d",stack[i]);
		}
	}
}
void main()
{ 
     int item,choice;
     char ch;
     do{
     	printf("BASIC OPERATION OF SATCK  :)\n");
     	printf("1. Insert item in stack :)\n");
     	printf("2. delete from stack :)\n");
     	printf("3. peep from stack :) \n");
     	printf("4. exit from stack :)\n");
     	printf("Enter the choice :)=");
     	scanf("%d",&choice);
     	switch(choice){
     	case 1:
     		printf("Enter the element :)");
     		scanf("%d",&item);
     		push(item);
     		break;
     	case 2:
     		pop();
     		break;
     	case 3:
     		peep();
     		break;
     	case 4:
     		printf("THANK YOU :)");
     		exit(0);
		 }
		 printf("\n DO YOU CONTINUE (Y/N) :)");
		 ch=getche();
		 printf("\n\n\n");
	 }
	 while(ch=='y');
}
Leave a Comment