[PR #1063] [CLOSED] Circular Queue_New #1621

Open
opened 2026-01-29 15:22:54 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/TheAlgorithms/C/pull/1063
Author: @akashissu
Created: 10/17/2022
Status: Closed

Base: masterHead: master


📝 Commits (2)

  • 2405b82 Circular queue solution
  • e1f8426 Merge 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");

else
{
    if (front == -1) 
        front = 0;
    
    rear = (rear + 1) % capacity;
    queue[rear] = value;
    printf("%d was enqueued to circular queue\n", value);

}
}

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.

## 📋 Pull Request Information **Original PR:** https://github.com/TheAlgorithms/C/pull/1063 **Author:** [@akashissu](https://github.com/akashissu) **Created:** 10/17/2022 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (2) - [`2405b82`](https://github.com/TheAlgorithms/C/commit/2405b82b1016934be7899c285368488b2927adf9) Circular queue solution - [`e1f8426`](https://github.com/TheAlgorithms/C/commit/e1f84264648f85395524a879cae5e385229f85c1) Merge pull request #1 from hussainiftikhar5242/hussainiftikhar5242-patch-1 ### 📊 Changes **1 file changed** (+92 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `data_structures/queue/CircularQueue.cpp` (+92 -0) </details> ### 📄 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"); else { if (front == -1) front = 0; rear = (rear + 1) % capacity; queue[rear] = value; printf("%d was enqueued to circular queue\n", value); } } 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; } --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 15:22:54 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#1621