Questions tagged [circular-list]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
212 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 ...
4
votes
3answers
8k views

Circular Singly Linked List using Java

Please review my implementation of a Circular Singly Linked List. ...
3
votes
1answer
41 views

Producer consumer with threads and using boost ring buffer

I have two threads, one is the producer and other is consumer. My consumer is always late (due to some costly function call, simulated in below code using sleeps) so I have used ring buffer as I can ...
13
votes
2answers
1k views

Asynchronous Circular Buffer in C#

Preamble I want to be able to test methods which communicate over a simple exclusively asynchronous two-way stream-like interface which may underneath use any of a number of communication methods (e....
4
votes
1answer
107 views

Simple ring/circular buffer c++ class V3

The Original Post (v2) As stated in the previous post, i'm looking for feedback on the updated version of the code posted. A few things specifically I'm looking for feedback on, are: I switched to ...
10
votes
2answers
9k 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 ...
4
votes
0answers
97 views

Simple ring/circular buffer c++ class V4

As the title states, this is my 4th revision of this class. Here is the previous post if needed. I'm hoping someone experienced with things such as noexcept, ...
2
votes
2answers
81 views

Simple ring/circular buffer c++ class V2

The Original Post (v1) I'm looking for feedback on the updated version of the code posted at the link above. ...
1
vote
1answer
132 views

Simple ring/circular buffer C++ class [closed]

I've got this simple ring/circular buffer class: ...
7
votes
2answers
222 views

Cyclic queue using an array

I tried to implement a cyclic Queue using an array, as a task from a coding interview. Please comment about style, as well as any edge cases I may have missed. ...
2
votes
2answers
39 views

Checking against a specific sequence in python

I'm trying to learn python and I'm modeling a simple dice game that a friend and I invented. On any one turn of the game, you must roll a specific combination to stay in the game. The particular ...
13
votes
2answers
1k views

Circular FIFO Buffer

I was bored the other day and got to wondering how I would implement a circular FIFO buffer in Rust. My goal was to create an implementation I could use on a bare metal microcontroller. This means no ...
17
votes
2answers
2k views

O(1) lock free container

This is a lock-free Container class. By Container I mean it will hold objects for iteration at a later time. To achieve \$O(1)\$ ...
3
votes
2answers
168 views

Circular Queue in C for an embedded project

I wrote a simple circular queue. (in order to store characters because of the fact, that I am using UART through the DMA and sometimes my printf's override each other) I am looking for some review, ...
5
votes
0answers
2k views

Disruptor pattern in a lock-free producer-consumer queue

I'm implementing a quick-and-dirty lock-free MPMC queue in C++, based on the v3 Disruptor algorithm. The implementation is pretty simple: Data to be shared between threads is stored in a ring buffer. ...
5
votes
5answers
43k views

Shift elements left by n indices in a list

For the following question, the function • should mutate the original list • should NOT create any new lists • should NOT return anything Functions that do not create new lists are ...
3
votes
2answers
208 views

Circular / Cyclic Buffer implementation

I am learning circular / cyclic buffer using this link. Here is the code that I have written so far: ...
0
votes
2answers
165 views

Josephus Problem with cyclic iterator

Given the Josephus Problem. Josephus Problem N people (numbered 1 to N) are standing in a circle. Person 1 kills Person 2 with a sword and gives it to Person 3. Person 3 kills Person 4 and ...
6
votes
3answers
4k 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: [...
12
votes
3answers
20k views

Circular RingBuffer

I am trying to get into C stuff, and I thought it would be a good idea to try and implement a circular buffer. I have defined my struct like this: ...
6
votes
2answers
3k views

Ring Buffer Implementation in C++14

A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than moving the data. Ring buffers are often used in embedded computer design. ...
2
votes
1answer
100 views

Find palindromes in circular rotated string

I'm trying to tackle a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm ...
5
votes
4answers
2k views

Survivor programming challenge

I am working on a survivor problem: Complete Question Text: Take a second to imagine that you are in a room with 100 chairs arranged in a circle. These chairs are numbered sequentially from One ...
29
votes
1answer
6k views

100 gunmen in a circle kill next person

I am very happy because I solved this problem with very little code: ...
4
votes
1answer
106 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 ...
2
votes
2answers
82 views

Looping text with directional control

The code is an implementation of looping text (similar to a circular buffer - wraps around when it reaches the edge of the defined bounds) with directional control. The code is functional and works ...
2
votes
1answer
40 views

Looping text in Python with directional control

The code is an implementation of looping text (similar to a circular buffer - wraps around when it reaches the edge of the defined bounds) with directional control. The code is functional and works ...
3
votes
2answers
362 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
2answers
246 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 ...
17
votes
3answers
20k views

Index into array as if it is circular

The problem: Treat an array as if it is circular; out-of-bounds indices "wrap around" the array to become in-bounds. Current solution: ...
6
votes
1answer
1k 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
238 views

Rotation view for std::vector

I have this view class for constant time rotations of a std::vector: ...
1
vote
2answers
5k views

Circular Queue Implementation Using Array in java

Here is my code of Array Implementation of Queue in java. ...
1
vote
3answers
1k 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 ...
5
votes
2answers
1k 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
0answers
494 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
272 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
933 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 ...
2
votes
1answer
4k views

Circular Linked List implementation in C++

I want to improve this code. ...
19
votes
2answers
3k 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 ...
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
1k 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
80 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 ...
4
votes
1answer
3k 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
623 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
522 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
453 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: ...
5
votes
1answer
683 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
2k 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
500 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 ...