Circular Queue in Data Structure with C Programming
| Circular Queue in Data Structure with C Programming |
//Circular Queue in Data Structure with C Programming
#include<stdio.h>
main()
{
int front=0,rear=0,n=6;
int queue[n];
int item;
//rear=rear-1%n;
//printf("rear= %d",rear);
while(1){
//take an item
printf("\nenter a value: ");
scanf("%d",&item);
//rear position increase
rear=(rear+1)%n;
//check queue is full or empty
if(rear==front){
rear=(rear-1)%n;
printf("\nthe queue is full.");
//printf("\n\nand r=%d",rear);
break;
}
//enqueue the item
else{
queue[rear]=item;
printf("\nthe input value is: %d \nand the index number is: %d",item,rear);
}
}
}
#include<stdio.h>
main()
{
int front=0,rear=0,n=6;
int queue[n];
int item;
//rear=rear-1%n;
//printf("rear= %d",rear);
while(1){
//take an item
printf("\nenter a value: ");
scanf("%d",&item);
//rear position increase
rear=(rear+1)%n;
//check queue is full or empty
if(rear==front){
rear=(rear-1)%n;
printf("\nthe queue is full.");
//printf("\n\nand r=%d",rear);
break;
}
//enqueue the item
else{
queue[rear]=item;
printf("\nthe input value is: %d \nand the index number is: %d",item,rear);
}
}
}
Circular Queue with user given size in Data Structure with C Programming
| Circular Queue with user given size |






0 comments:
Post a Comment