Questions tagged [circular-list]
A circular list may be implemented using a fixed-size array (a ring buffer) or a linked list.
151
questions
1
vote
1
answer
999
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
1
answer
7k
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
1
answer
1k
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
2
answers
1k
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
2
answers
816
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
1
answer
1k
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 ...
7
votes
2
answers
7k
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
3
answers
867
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
2
answers
6k
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,...
7
votes
3
answers
12k
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:
[...
9
votes
1
answer
186
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 ...
7
votes
1
answer
2k
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 ...
1
vote
1
answer
2k
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
2
answers
10k
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 ...
4
votes
1
answer
1k
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
1
answer
3k
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
4
answers
5k
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
1
answer
556
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
1
answer
86
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
1
answer
71
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
2
answers
308
views
Rotation view for std::vector
I have this view class for constant time rotations of a std::vector:
...
5
votes
1
answer
606
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
2
answers
4k
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
1
answer
168
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 ...
6
votes
2
answers
3k
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
5
answers
5k
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:
...
12
votes
3
answers
41k
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 ...
11
votes
2
answers
14k
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
3
answers
10k
views
Circular Singly Linked List using Java
Please review my implementation of a Circular Singly Linked List.
...
4
votes
3
answers
25k
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 ...
3
votes
0
answers
704
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
2
answers
2k
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
3
answers
485
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.
...
12
votes
5
answers
658
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 ...
18
votes
1
answer
2k
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
1
answer
241
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.
...
4
votes
3
answers
737
views
Implementing CircularQueue using Linked List in C++
I'm currently doing a project, requiring me to implement a CircularQueue data structure in C++:
...
2
votes
1
answer
761
views
Doubly circular linked list implementation
I made this C++ doubly circular linked list implementation and it seems to work right, handle everything well, and not have any errors. However, I've been working with it for a while and would like ...
2
votes
1
answer
912
views
Circular array list in C
Now I have this circular array-based list in C. Circularity allows pushing/popping to the both ends of the list in constant amortized time. Inserting/removing at random locations runs in linear time, ...
7
votes
1
answer
944
views
Stack using an array
I designed a simple drop-out stack a while back. Basically, I just want to get a few opinions on whether or not this is a good implementation and whether I am understanding the concept of a drop-out ...
5
votes
3
answers
1k
views
Finding the tallest and find the index number of the next taller guy in a circular queue
Input given is:
Each test case contains two lines. The first line contains a single integer N (1 ≤ N ≤ 105), the number of persons playing the game. The second line contains N integers i(height) (1 ...
2
votes
3
answers
170
views
ADT Stack with a doubly circular linked list
I have managed to implement an ADTStack with a circular doubly linked list. I would like to know whether there are things I could have done better or, I should ...
3
votes
2
answers
1k
views
Ring buffer for audio processing (follow up)
This question is a follow up in regards to the comments suggested in a previous post regarding a Ringbuffer implementation in C++ for audio processing.
Ring buffer ...
7
votes
2
answers
3k
views
Ring buffer for audio processing
Below is my source code for the implementation of a Ring/Circular buffer for use in audio processing. I have been using this implementation for several months now but I have some doubts about the ...
3
votes
2
answers
1k
views
Linear Probing in Python
About to get back into coding, so I implemented linear probing in Python. How did I do? Anything unnecessary? Am I using "global" right? I originally wanted to use an array with a fixed length, but ...
3
votes
1
answer
4k
views
Array slice type in Java
Edit See the next iteration at Array slice type in Java - follow-up.
I have this "slice" type for managing array subranges. It is kind of the same thing as Pythons slice notation, yet I did not add ...
5
votes
0
answers
185
views
Ring Buffer using templates/macros
I just wrote my first Nim module and was hoping someone with some experience with Nim or similar languages could take a look. In particular I was hoping someone could speak if the use of ...
5
votes
5
answers
63k
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 said to be ”in ...
5
votes
4
answers
3k
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 ...
32
votes
1
answer
8k
views
100 gunmen in a circle kill next person
I am very happy because I solved this problem with very little code:
...