Updated: Mar 28, 2023
top of page
Updated: Mar 28, 2023
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#define size 100
int queue[size];
int top=-1;
void enque(void);
void deque(void);
void peek(void);
void isEmpty(void);
void isFull(void);
void display(void);
void main() {
int c,e;
do{
switch(c)
{
case 1:
enque();
break;
case 2:
deque();
break;
case 3:
peek();
break;
case 4:
isEmpty();
break;
case 5:
isFull();
break;
case 6:
display();
break;
case 7:
printf("\n\n----Exit from program successfully----");
printf("\n--------------Thank you--------------");
exit(0);
}
printf("\n1 : Enque\n2 : Deque\n3 : Peek\n4 : isEmpty\n5 : isFull\n6 : Display");
printf("\nEnter your choice : ");
scanf("%d",&c);
}while(c);
}
void enque()
{
int v;
printf("\nEnter value : ");
scanf("%d",&v);
if(top==size-1)
{
printf("\nQueue is full!!");
}
else
{
top++;
queue[top]=v;
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nQueue is empty");
}
else
{
for(i=0;i<=top;i++)
{
printf("--%d",queue[i]);
}
}
}
void deque()
{
if(top==-1)
{
printf("\nQueue is empty!!");
}
else
{
int i;
for(i=0;i<=top;i++)
{
queue[i]=queue[i+1];
}
top--;
}
}
void peek()
{
printf("\nTop : %d",top);
printf("\nTop Value: %d",queue[top]);
}
void isEmpty()
{
if(top==-1)
{
printf("\nQueue is empty!!");
}
else
{
printf("\nQueue is not empty!!");
}
}
void isFull()
{
if(top==size-1)
{
printf("\nQueue is full!!");
}
else
{
printf("\nQueue is not full!!");
}
}
2 views0 comments
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#define size 100
int stack[size];
int top=-1;
void push(void);
void pop(void);
void peek_top(void);
void isEmpty(void);
void isFull(void);
void display(void);
void max(void);
void min(void);
void main() {
int c,e;
do{
switch(c)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peek_top();
break;
case 4:
isEmpty();
break;
case 5:
isFull();
break;
case 6:
display();
break;
case 7:
max();
break;
case 8:
min();
break;
case 9:
printf("\n\n----Exit from program successfully----");
printf("\n--------------Thank you--------------");
exit(0);
}
printf("\n1) Push\t2) Pop\t3) Peek\t4) isEmpty\t5) isFull\t6) Display\t7) Maximum\t8) Minimum\t9) Exit");
printf("\n\nEnter your choice : ");
scanf("%d",&c);
}while(c);
}
void push()
{
int v;
printf("\nEnter value : ");
scanf("%d",&v);
if(top==size-1)
{
printf("\nStack is full!!");
}
else
{
top++;
stack[top]=v;
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nStack is empty");
}
else
{
for(i=0;i<=top;i++)
{
printf("--%d",stack[i]);
}
}
}
void pop()
{
if(top==-1)
{
printf("\nStack is empty!!");
}
else
{
top--;
}
}
void peek_top()
{
printf("\nTop : %d",top);
printf("\nTop Value: %d",stack[top]);
}
void isEmpty()
{
if(top==-1)
{
printf("\nStack is empty!!");
}
else
{
printf("\nStack is not empty!!");
}
}
void isFull()
{
if(top==size-1)
{
printf("\nStack is full!!");
}
else
{
printf("\nStack is not full!!");
}
}
void max()
{
int mx=stack[0];
int i;
for(i=0;i<=top;i++)
{
if(mx<stack[i])
{
mx=stack[i];
}
}
printf("\nMaximum value : %d",mx);
}
void min()
{
int mn=stack[0];
int i;
for(i=0;i<=top;i++)
{
if(mn>stack[i])
{
mn=stack[i];
}
}
printf("\nMinimum value : %d",mn);
}
2 views0 comments
bottom of page