Questions tagged [circular-queue]

Tag for questions about Circular Queues. They are linear FIFO data structures in which the last position is connected back to the first position to make a circle. Also known as "circular buffer", "cyclic buffer", "ring buffer".

A Circular Queue (also known as "circular buffer", "cyclic buffer", "ring buffer") is a linear data structure which operates using the FIFO (First In First Out) principle. The particularity of Circular Queues is that the last position is connected back to the first position to make a circle.

37 questions
0
votes
0 answers

Popping an element from circular queue in C

So, i tried to delete a particular element in a circular queue, and used its index as front and back. When I ran the code: #include #include #include #define size 6 int cir_queue[size]; int front = -1, rear = -1; //…
0
votes
1 answer

In a circular queue how to check if the iterator is greater than and equal to the front element of the queue

struct PCB { int PID; int burstTime; int arrivalTime; int priorityScore; int startTime; int finishTime; }; struct Queue { int front; int rear; int length; // Stores the maximum no. of processes that can be…
0
votes
1 answer

why does my dynamically allocated array implementation of queue data structure NOT update on the second call?

I'm learning Data Structures as required of me by my university. I've implemented the Queue DS using Dynamic Array but it somehow doesn't work. It updates the value on the first enqueue method call but from the second call onward, it does…
0
votes
0 answers

Unable to display elements in circular queue

I am learning circular queue and I am facing some error. While displaying the queue it only shows the first and last element, after deleting an element it gets even worse, now I don't know where exactly I am going wrong if it's while inserting an…
0
votes
1 answer

How can I display dequeued items in a Circular Queue?

I need to make a program that can keep track of dequeued elements. I was thinking of using three instances of the CircularQueue class, one for all customers as they arrive at the my shop, another two for serving the next customer at counter A and…
kratos00
  • 1
  • 1
0
votes
1 answer

Python initialize a list in a class

I am trying to solve a leetcode question using list: Design Circular Queue. But it throws an error: IndexError: list assignment index out of range self.queue[self.tail] = value My code: class MyCircularQueue: def __init__(self, k: int): …
yinqi
  • 41
  • 4
0
votes
1 answer

AJAX does not return anticipated response

I'm trying to start to use AJAX to send a Javascript variable from one PHP file to another that will enqueue it to a queue function I have created and then peek that ID in the queue by changing the < p > tag in my main file EDIT: I get an error…
rxm
  • 71
  • 2
  • 11
0
votes
1 answer

Explanation for the following expected circular queue result

I'm trying to create a circular queue and come across this problem. As you see, my answer is incorrect. I still don't understand the reason why it is the case, so let's go through everything again. Create a circular queue of size 2 Enqueue 8,…
Hung Vu
  • 443
  • 3
  • 15
0
votes
1 answer

Any idea why this function is defined like this in a circular queue?

I am currently studying circular cues. I came across these functions while studying using the textbook. int NextPosIdx(int pos) { if (pos == QUE_LEN -1) return 0; else return pos +1; } Looking at the algorithm, I wrote these…
bombo
  • 47
  • 5
0
votes
3 answers

Insert and Delete element on Circular Queue

I'm studying about circular queue in data structure . As you can see from the code below, I try to delete a specific data and insert data on Circular queue. However, when I try to run it there's a problem when deleting data and insert a new one. I…
Max P Apth
  • 15
  • 1
  • 7
0
votes
2 answers

Why is the variable value changing automatically?

This is my code int front=-1, rear=-1, CQUEUE[MAX]; int isFull() { if((rear=MAX-1 && front==0) || front==rear+1) return 1; else return 0; } void enQueue() { printf("\nValue of rear=%d…
Sathvik K S
  • 109
  • 1
  • 2
  • 11
0
votes
1 answer

An efficient way to implement circular priority queue?

I have designed a circular priority queue. But it took me a while because it is so conditional and has a bit much of a time complexity. I implemented it using a list. But I need a more efficient circular priority queue implementation. I'll…
Clarke
  • 185
  • 10
0
votes
1 answer

implementing a copy constructor, destructor, and how to overload assignment operator for queues

This is what i have, but i am not sure that this works. I am not sure if copying this way is efficient,and i couldn't figure a way to overload. when copying, i am giving both the same size, setting header and tail(indexes of first and last element)…
0
votes
1 answer

EnQueue method not returning correctly in C++ circular queue?

I have less than 3 months experience coding, so I've started using LeetCode to just build hours working with code beyond what's assigned in school. I was working on trying to build a circular queue (FIFO), and it won't compile. I received the…
0
votes
0 answers

How to display the elements of a Circular Queue in an efiicient (circular) manner?

Most of the programs that I saw produced the results in a linear manner , like displaying a normal one-dimensional array. But here I have a circular queue, and the elements in it must be displayed LIKE a circular queue.