Skip to content

Instantly share code, notes, and snippets.

@ashwath007
Created August 6, 2021 17:51
Show Gist options
  • Save ashwath007/1bc3f70aedb0a699640e1d19949628a5 to your computer and use it in GitHub Desktop.
Save ashwath007/1bc3f70aedb0a699640e1d19949628a5 to your computer and use it in GitHub Desktop.
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#define M 5
// 0 -> Stack
// 1 -> Queue
int Swords[M];
char Qwords[M];
int STop=0, QTop=0, Back=0;
int isFull(int type);
int isEmpty(int type);
// Stack
void push();
void pop();
// Queue
// void enQueue();
// void deQueue();
// Dis
void Dis();
int main()
{
// Queue
int n = 1,ele,ele1,ele2;
while(n){
printf("Enter the option : \n \t 1. Stack \n \t 2. Queue\n");
scanf("%d",&ele);
switch(ele){
case 1:
printf("Enter the option : \n \t 1. Push \n \t 2. Pop");
scanf("%d",&ele1);
switch(ele1){
case 1:
push();
Dis();
break;
case 2:
pop();
Dis();
break;
}
break;
case 2:
printf("Enter the option : \n \t 1. EnQuque \n \t 2. DeQuque\n");
scanf("%d",&ele2);
switch(ele1){
case 1:
// enQueue();
break;
case 2:
// deQueue();
break;
}
break;
}
}
return 0;
}
int isFull(int type){
if(type == 0){
if(STop == M-1 ){
return 1;
}
else return 0;
}
}
int isEmpty(int type){
if(type == 0){
if(STop == 0 ){
return 1;
}
else return 0;
}
}
void push(){
int letter;
printf("Enter the char : ");
scanf("%d",&letter);
getchar();
if(isFull(0)){
printf("\n\tStack is full \n");
}
else{
Swords[STop] = letter;
STop++;
}
}
void pop(){
if(isEmpty(0)){
printf("\n\tStack is empty \n");
}
else{
Swords[STop] = 0;
STop--;
}
}
void Dis(){
for(int y=0;y<STop ;y++){
printf("| %d | -> ",Swords[y]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment