Questions tagged [circular-list]

In a circularly linked list, all nodes are linked in a continuous circle, without using null. For lists with a front and a back (such as a queue), one stores a reference to the last node in the list.

In a circularly linked list, all nodes are linked in a continuous circle, without using null. For lists with a front and a back (such as a queue), one stores a reference to the last node in the list. The next node after the last node is the first node. Elements can be added to the back of the list and removed from the front in constant time.

Circularly linked lists can be either singly or doubly linked.

Both types of circularly linked lists benefit from the ability to traverse the full list beginning at any given node. This often allows us to avoid storing firstNode and lastNode, although if the list may be empty we need a special representation for the empty list, such as a lastNode variable which points to some node in the list or is null if it's empty; we use such a lastNode here. This representation significantly simplifies adding and removing nodes with a non-empty list, but empty lists are then a special case.

332 questions
51
votes
10 answers

Why exactly do we need a "Circular Linked List" (singly or doubly) data structure?

Why exactly do we need a "Circular Linked List" (singly or doubly) data structure? What problem does it solve that is evident with simple Linked Lists (singly or doubly)?
user366312
  • 17,582
  • 55
  • 198
  • 392
26
votes
4 answers

Does a standard implementation of a Circular List exist for C++?

I want to use a circular list. Short of implementing my own (like this person did) what are my options? Specifically what I want to do is iterate over a list of objects. When my iterator reaches the end of the list, it should automatically return…
Runcible
  • 6,126
  • 9
  • 38
  • 58
20
votes
3 answers

What is the difference between a cyclic list and an infinite list in haskell?

Referencing @dfeuer's answer to this question: Least expensive way to construct cyclic list in Haskell, which says that using cyclic lists 'defeats' the garbage collector as it has to keep everything you've consumed from a cyclic list allocated till…
Ramith Jayatilleka
  • 2,072
  • 12
  • 25
17
votes
5 answers

Circular ArrayList (extending ArrayList)

So my program has a need of a type of circular ArrayList. Only circular thing about it has to be the get(int index) method, this is the original: /** * Returns the element at the specified position in this list. * * @param index…
Karlovsky120
  • 5,718
  • 7
  • 30
  • 79
13
votes
4 answers

Iterating circular way

I need iterate through a List but circular way. I need too add new elements to the list and iterate over all elements (olds and news elements), How I do it? Is there any data structure for them?
barroco
  • 2,858
  • 4
  • 25
  • 38
13
votes
5 answers

What are circular lists good for (in Lisp or Scheme)?

I note that Scheme and Lisp (I guess) support circular lists, and I have used circular lists in C/C++ to 'simplify' the insertion and deletion of elements, but what are they good for? Scheme ensures that they can be built and processed, but for…
philcolbourn
  • 3,670
  • 3
  • 26
  • 31
13
votes
3 answers

How to implement a round-robin circular list and count access requests of an element?

Scenario: For a list that have 3 elements: [A, B, C] You can circular access it as many times as you want. And there is an additional counting function records access count of each element. For example, if accessing it 7 times, should return: [A,…
Wuaner
  • 833
  • 1
  • 13
  • 29
13
votes
2 answers

Circular LinkedList implementation in Java

This is an assignment. I have to create a circular linked list and remove every third number in the list. When my program reaches the end of the list it should go back to the head and continue the process until only one number remains. I've searched…
LPlateJava
  • 171
  • 1
  • 2
  • 9
11
votes
7 answers

How should I define a good hashCode for a circular linked list in Java?

I have set up a circular linked list data structure that represents a word, and each element in the list is a letter from the word. At the bottom of my question are the class definitions of the list and element of the list. The purpose of the list…
Hristo
  • 42,002
  • 60
  • 155
  • 224
10
votes
3 answers

Can I use java.util.LinkedList to construct a circular/cyclic linked list?

I would like to create a circular/cyclic linked list where the tail of the list would point back to the head of the list. So can I use java.util.LinkedList and modify the tail node after creation of the list to make it circular/cyclic? If so, can…
Hristo
  • 42,002
  • 60
  • 155
  • 224
9
votes
1 answer

What is the difference between a Ring Buffer and a Circular Linked List?

What is the difference between a Ring Buffer and a Circular Linked List? What purpose does Ring Buffer serve that Circular Linked List cannot or vice versa?
user366312
  • 17,582
  • 55
  • 198
  • 392
9
votes
3 answers

Circular list in Common Lisp

I am working using a visual programming environment for musical composition based on CL . I am trying to create a function that when given say 3 elements (1 2 3) will return 1, 2, 3, 1, 2, 3 etc., one number at the time each time it is evaluated.…
8
votes
5 answers

Efficient circular list

I want a simple yet efficient circular buffer/queue. If I use std::vector, I have to do this: if ( v.size() >= limit ) { std::vector it = v.begin(); v.insert( it, data ); v.erase( it+1 ); } Is there any simpler solution?
mahmood
  • 19,156
  • 36
  • 118
  • 190
8
votes
5 answers

How to Create a Circular LinkedList

I know how to create the Link and LinearLinkedList classes, but I just cannot for the life of me figure out how to modify them into a creating circularlinkedlist. I have already read the answer to this question. However, I do not understand how if…
Colosus__
  • 83
  • 1
  • 1
  • 5
7
votes
2 answers

How to use a ring data structure in window functions

I have data that is arranged in a ring structure (or circular buffer), that is it can be expressed as sequences that cycle: ...-1-2-3-4-5-1-2-3-.... See this picture to get an idea of a 5-part ring: I'd like to create a window query that can…
Mike T
  • 34,456
  • 15
  • 128
  • 169
1
2 3
22 23