mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-09-23 15:34:20 +00:00
[PR #1063] [CLOSED] Circular Queue_New #1621
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/TheAlgorithms/C/pull/1063
Author: @akashissu
Created: 10/17/2022
Status: ❌ Closed
Base:
master← Head:master📝 Commits (2)
2405b82Circular queue solutione1f8426Merge pull request #1 from hussainiftikhar5242/hussainiftikhar5242-patch-1📊 Changes
1 file changed (+92 additions, -0 deletions)
View changed files
➕
data_structures/queue/CircularQueue.cpp(+92 -0)📄 Description
#include <stdio.h>
#define capacity 6
int queue[capacity];
int front = -1, rear = -1;
int checkFull(){
if ((front == rear + 1) || (front == 0 && rear == capacity - 1)){
return 1;
}
return 0;
}
int checkEmpty(){
if (front == -1)
{
return 1;
}
return 0;
}
void enqueue(int value){
if (checkFull())
printf("Overflow condition\n");
}
}
int dequeue() {
int variable;
if (checkEmpty()) {
printf("Underflow condition\n");
return -1;
}
else
{
variable = queue[front];
if (front == rear) {
front = rear = -1;
}
else {
front = (front + 1) % capacity;
}
printf("%d was dequeued from circular queue\n", variable);
return 1;
}
}
void print(){
int i;
if (checkEmpty())
printf("Nothing to dequeue\n");
else
{
printf("\nThe queue looks like: \n");
for (i = front; i != rear; i = (i + 1) % capacity)
{
printf("%d ", queue[i]);
}
printf("%d \n\n", queue[i]);
}
}
int main() {
dequeue();
enqueue(15);
enqueue(20);
enqueue(25);
enqueue(30);
enqueue(35);
print();
dequeue();
dequeue();
print();
enqueue(40);
enqueue(45);
enqueue(50);
enqueue(55);
print();
return 0;
}
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.