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
2
votes
3answers
1k views

“Fun with Rotation” - Codechef September Challenge

Can you please help me in reducing the complexity of the below code? The problem statement can be found here. You are given an array A of N integers. You are to fulfill M queries. Each query has ...
2
votes
2answers
2k views

Safely getting the next element of a list

I'm looking for general review and improvements on this code that safely gets the next element of a list (and wraps to the first element if you exceed the list). It just seems a little excessive for ...
2
votes
3answers
19k views

Josephus Problem in Java

Problem The Josephus Problem is a famous mathematical puzzle that goes back to ancient times. There are many stories to go with the puzzle. One is that Josephus was one of a group of Jews who ...
15
votes
1answer
1k views

CircularListCursor - an efficient circular cursor on any list

I have decided to create my own CircularListCursor, because I wanted some abstraction and a ListIterator<E> couldn't give ...
1
vote
2answers
241 views

Is this circular linked list better than the fast & slow pointer method?

I have a faster way to find if a list is circular linked list, in contrast to the solution that Cracking the Coding Interview has offered: In the below algorithm, ...
3
votes
2answers
4k views

Displaying items in a circular queue

I am dealing with the following problem: Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. ...
17
votes
3answers
19k 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: ...
11
votes
3answers
9k views

Doubly-Linked Circular Linked List

I'm a C++ programmer learning Java in preparation for an OOP class this fall. That being said, Java is fairly new to me so I'd love to hear feedback on how to improve this code. A few notes: Code ...
5
votes
1answer
534 views

Microcontroller ringbuffer

I'm pretty new to microcontrollers and C in general, so I thought asking here would be a good way not to get started with bad habits. ...
5
votes
5answers
21k views

Circular queue implementation

I've implemented a simple thread-safe circular queue. I'm looking for code review, optimizations and best practices. ...
5
votes
1answer
3k views

Single consumer and single producer lock-free circular buffer

I'm pretty new to multithreading. The code below is a simple implementation of a single consumer/single producer circular buffer that does not use any locking, that I wrote for fun. The question is,...
6
votes
2answers
1k views

Ring buffer in Ruby

I was just reading about ring buffer the other day and I was fascinated by how simple yet efficient it is. I've implemented a ring (circular) buffer in Ruby and I'm just wondering if there's anything ...
7
votes
2answers
1k views

Counting number of nodes between two nodes

This code counts the number of nodes between any given two nodes in a circular linked list. Any feedback is appreciated: ...
5
votes
2answers
531 views

Circular linked list of integers

I'm looking for a review paying special attention as to whether the code can be optimized in the form of number of variables used, especially for the delete() ...
12
votes
5answers
16k views

One reader / one writer no-memory-allocation lock-free ring-buffer

I have two threads - one thread queues items another thread dequeues. dequeue is fast enough and so we can assume that queue is never contains more than 65536 items....
3
votes
3answers
849 views

Unbounded, High-performance(?), Generic, Thread-Safe(?), BatchedCircularQueue

This is a data structure I wrote: It is an circular first-in-first-out queue (a ringbuffer); It has batched removal/popping - it returns an array of a fixed buffer size; It is unbounded, and ...
3
votes
1answer
10k views

Insert in circular linked list

Please review my code. ...
2
votes
1answer
407 views

Inky pinky ponky game / Josephus problem

I have written below code for the famous Josephus problem, or inky pinky ponky game, or many other names. Does this looks good or is there any loophole if anyone can highlight. I shall be looking ...
6
votes
2answers
13k views

Thread-safe message queue without mutex in C

I'm trying to write a message queue implementation so my threads can exchange data. To keep things simple, the queue is only responsible for sending pointers to memory. Only one thread may send ...
1
vote
1answer
20k views

Doubly circular link list implementation

I am supposed to be creating a doubly circular linked list, but I am now have problems creating the actual linked list. Is there a problem with the classes? Also, for the assignment, the list is ...
3
votes
1answer
539 views

Circular Buffer on a typed Float32Array

I am sure there are better ways to do things but this is part of my first JavaScript project and I'm slowly getting accustomed with how things work in JavaScript. This is also why I ask for a code ...
6
votes
1answer
4k views

Multi threaded circular buffer

I've written a circular buffer with multithreaded write and single read ability: ...
4
votes
3answers
3k views

Lock free MPMC Ring buffer implementation in C

I have written a lock free MPMC FIFO in C based on a ring buffer. It uses gcc's atomic built-ins to achieve thread safety. The queue is designed to return -1 if it's full on enqueue or empty on ...
7
votes
2answers
5k views

Circular buffer implementation for buffering TCP socket messages

I have written my own for practice and also some tweaks for my specific requirement. There is an insert which can copy a range (well array copy really) which I am hoping is more efficient than ...
2
votes
2answers
3k views

Lock-Free Ring Implementation

I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger. The CircularRing pre-...
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: ...
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)\$ ...
2
votes
1answer
2k views

Ring buffer in C tail pointer issue (for audio streaming)

I am currently writing an embedded application for audio streaming purposes. The embedded app will receive audio packets being sent over WiFi, buffer the packets, then send the audio data over to a ...
5
votes
2answers
18k views

Producing every string of a given length using some range of characters

Ever since I was a kid I wanted to understand how brute force programs work. I have not been able to make sense of any of the examples throughout the internet, so it became a personal challenge to ...
4
votes
3answers
29k views

Circular linked list

Please review this: ...
10
votes
4answers
5k views

Circular Bounded Queue using C#

As an exercise, I have implemented a circular bounded queue using arrays as the base data structure. I'd appreciate it if someone can review it for me. ...