Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [circular-list]

A circular list may be implemented using a fixed-size array (a ring buffer) or a linked list.

3
votes
2answers
160 views

Customized lock-free RingBuffer

I have implemented my own lock-free ringbuffer for multiple producers multiple consumers using vector. Can you guys help me review to see if there are any problems and ways to improve? Explanation: ...
3
votes
1answer
54 views

JavaScript circular linked list compatriot game

I found this question in O'Reilly Data Structure and Algorithm in Javascript: According to legend, the first-century Jewish historian Flavius Josephus was about to be captured along with a band ...
5
votes
1answer
179 views

Multiple-producer, single-consumer lock-free circular queue

I'm working on a firmware on a bare-metal ARM single core processor (Cortex M4), with no RTOS. I need to add a multiple-producer, single-consumer, lockless fixed-size circular (ring) buffer to the ...
2
votes
2answers
76 views

Find the sum of all digits that match the following digit in a circular list

The challenge The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit ...
1
vote
2answers
1k views

Circular Queue Implementation Using Array in java

Here is my code of Array Implementation of Queue in java. ...
5
votes
2answers
800 views

Compare two lists to see if one is a rotation of the other

Going through a list of common interview question, this was the next one. Any suggestions on performance and improvement? What would be a better implementation of this? Also correct me if I'm wrong, ...
1
vote
3answers
580 views

Deque implemented using a circular array

I found a tutorial on implementing a deque using a circular array. I changed the implementation but I am not sure if it is correct or not. So I have one question: I wrote code that uses an ...
1
vote
0answers
199 views

Really basic ring/circular buffer in Java

I needed a simple way to run tests on the last n bytes of data received from a socket, and a ring buffer seemed to be the most efficient way to handle it. This is a very basic buffer that stores ...
1
vote
1answer
135 views

Split Circular linked list into two halves

I want to improve this code. I want to enter all values in linked list at a time like circular_linked_list<int> cll1(5, 10, 18, 25); ...
2
votes
1answer
380 views

Circular Doubly Linked List

After improving code from suggestions to my previous question. I have implemented copy constructor, copy assignment, move constructor, move assignmnet. There is a suggestion for sentinal node but I ...
0
votes
1answer
2k views

Circular Linked List implementation in C++

I want to improve this code. ...
3
votes
2answers
169 views

SPOJ Class Leader using circular linked list

I have solved a spoj question CLASS LEADER. For each test case there are n students and a paper will be given to student m and now the game starts, the student m will pass the paper by o positions ...
10
votes
4answers
2k views

Advent of Code 2017, Day 1: Sum of digits matching the next digit (circular list)

I haven't used C++ for quite a while and wanted to practice a bit, so I decided to start simple and work through the Advent of Code 2017. This is my solution to Part 1 of the Day 1 exercise "Inverse ...
1
vote
1answer
302 views

C Implementation of dynamic mem allocation using first-fit algo

I have implemented malloc and free in C based on first-fit algo and using a circular linked list for free blocks of memory. It seems to be working based on the basic test in the main function. I would ...
1
vote
1answer
61 views

CodeChef Fusing Weapons in a circular list

I am currently trying to solve this problem on Codechef: Before the start of each stage, N weapons appear on the screen in circular order. Each weapon has an integer associated with it, which ...
2
votes
1answer
919 views

Best way of implementing a circular buffer

I wanted to implement a circular buffer for learning purpose only. My first option was to use a secondary status for rear and front pointers: (Like the ones I've seen in many websites) ...
1
vote
1answer
327 views

Implementation of IPC circular buffer

For a school assignment we had to implement IPC between two processes using File Maps with some specific requirements. The relevant requirements are: ComLib will send a null-terminated (C-style) ...
3
votes
2answers
224 views

Implementation of a Resizing Array Queue

Below is a problem from Sedgewick's Algorithms and my solution. Any thoughts or suggestions for improvement would be much appreciated. Develop a class that implements the queue abstraction with a ...
0
votes
2answers
192 views

Binary protocol print utility in C++

Please review this protocol printer/decoder in C++. I also attached a sample binary file to use to test. Main program: ...
4
votes
1answer
473 views

Non blocking single producer/consumer queue with C++11 atomics

I've recently got interested in lockless programming, mainly lockless queues for job repartitions, so here I undertook a challenge of creating lockless queue for single producer and consumer. This is ...
4
votes
1answer
1k views

C++ Circular buffer through Circular iterator

I saw some question on SO lately involving circular buffer, like a chain of descriptors for data transfer. All solutions involved lots of lines. I wanted an implementation with as few lines as ...
4
votes
3answers
407 views

Producer-Consumer with Peterson algorithm in java

Producer-consumer problem in Java with a circular buffer of N positions. There is a single thread representing the producer that will produce consecutive integer elements There is a dimensioned ...
8
votes
2answers
1k views

Circular Buffer C++ Implementation

I was asked this question in an interview, and didn't go through. I know, it needs some improvements, but probably I am missing something big? I would highly appreciate if someone can review it for me,...
3
votes
1answer
927 views

Elegant Circular Buffer

I would like to design an elegant yet efficient circular buffer of integers. I have designed a FIFO type circular buffer in C++(11)- starting with the class header (declaration) as follow: [...
8
votes
1answer
117 views

Rotate a given number of variables in-place

A very simple but useful algorithm: rotate the values of a given number of variables in-place to the left so that the first variable gets the value of the second, the second gets the value of the ...
5
votes
1answer
595 views

Implementation of fixed size queue using a ring (cyclic) buffer

I found myself in need of a fixed size queue and decided to implement one using a ring (cyclic) buffer. I have tried my best to match the API of std::queue with ...
0
votes
1answer
903 views

Deleting the head node of a circular linked list

Today I tackled this coding challenge: Given a circular linked list, implement a method to delete its head node. Return the list's new head node. I would appreciate any feedback. ...
19
votes
2answers
1k views

A Python wrap-around list

I want to gain experience creating data structures that look and feel like Python builtin types. As a first exercise, I've written a WraparoundList class meant to ...
5
votes
1answer
497 views

Circular doubly linked list with templates

I tried to write some code namely "Circular doubly linked list" and I would like to use templates to do this. This is the first time I use templates and throws some exceptions. I would like to know ...
2
votes
1answer
2k views

Implementing a queue using a circular buffer

I'm working on implementing a queue using a circular buffer problem. Any smarter ideas for better time complexity, any code bug or code style advice are highly appreciated. ...
3
votes
4answers
2k views

Circular array rotation Java

I have a solution to the HackerRank Circular Array Rotation challenge. It passes 7 test cases out of 15. The rest of them are getting timed out. I think it's because of the huge data set that has ...
0
votes
1answer
198 views

Shift an element in a circular container

I implemented a function to shift an element after another in a logical circular array. Shifting in this case simply means moving element at position i to in front ...
2
votes
1answer
68 views

Invert-range operation in a circular vector

I implemented a invert-range operation in a (logical) circular vector. A circular vector is a vector without a logical starting and ending object, or, equivalently, the successive element of the ...
1
vote
1answer
43 views

Delete the node at index i from its current position and insert it after node at index j

I was trying to create a function to delete the node at index i from its current position and insert it after node at index j ...
2
votes
2answers
202 views

Rotation view for std::vector

I have this view class for constant time rotations of a std::vector: ...
4
votes
1answer
300 views

Circular doubly linked list in JavaScript

I've been studying data structures and have taken a stab at implementing a doubly LL in JavaScript. Please review and advise on any additional improvements and optimizations. I'm more interested in ...
4
votes
2answers
1k views

Circular buffer implementation using linked list

I'm a beginner with C. The below is the implementation of circular buffer using linked list. Please review my code and suggest any improvements to make it efficient or to improve in coding style. <...
4
votes
1answer
82 views

Rotating list in python

This is a list class which allows users to "turn" the list while keeping track of the current position. For efficiency, the list is not actually rotated on each rotation, but instead an offset keeps ...
3
votes
2answers
2k views

constant sized circular (ring) buffer

I've implemented constant sized circular buffer. It provides push and pop operations, along with modern emplace. It is also optimized for destruction of trivially destructible types. I didn't include ...
6
votes
5answers
2k views

A buffer that holds and provides the latest n items

I have developed the following code to hold n latest items it has received, and when asked for provide these n latest items. The interface is: ...
9
votes
3answers
20k views

Circular Buffer C++11 Implementation

Here's the implementation of a common data structure I use at work, mainly for logging purposes. I tried to make it C++11-compliant, but even if this standard has been around for a few years, it is ...
9
votes
2answers
5k views

Circular Buffer Implementation

I'm implementing a "live analytics" feature and I need to always keep track of the last N items that were added to a collection so I figured I'd make a circular buffer since I couldn't find one. I ...
2
votes
2answers
5k views

Circular Singly Linked List using Java

Please review my implementation of Circular Singly Linked List ...
3
votes
3answers
6k views

“Prev” / “Next” buttons for a circular list

I have an array of strings and on click of the "NEXT" button it displays the next array item in a <p> tag while on click of the "PREV" button it displays the ...
2
votes
0answers
399 views

Concurrent resizable ring buffer

I'm trying to find the fastest way to enqueue and dequeue items concurrently in Go. There are some restrictions: it needs to be unbounded Memory allocation should be low Multiple producers (Single ...
10
votes
2answers
1k views

Circular Buffer in C - Follow Up

This is a follow up to this post I uploaded a few days back on my alternative account about a circular buffer in C. I'm confident that I fixed most of the warnings and even added an iterator. ...
8
votes
3answers
303 views

Circular Buffer

For my current project I need a circular buffer, which is able to do the following things: Push something to it (to the head). Pop something from it (from the tail). I don't need the popped data. ...
11
votes
5answers
581 views

FiniteArrayQueue type with interface and unit tests

Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
16
votes
1answer
988 views

C and CUDA: circular buffer implementation

I have a programme which uses many circular buffers in an identical fashion on a CPU and GPU (C and C/C++ CUDA). I essentially require many queues, however, due to this being run on a GPU, I have ...
6
votes
1answer
135 views

Rate limiting function calls

I wanted to write a function that when applied to another would rate limit it, but permit all calls to eventually make it through. Comments and criticism welcome. ...