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
4
votes
7 answers

How to delete elements of a circular list until there is only one element left using python?

How would I go about iterating through a list from 1-100, where I delete every other element starting with the first element, and repeat that step until there in only one element left in the list. Would I have to use a circular linked list, or can…
stochasticcrap
  • 329
  • 3
  • 15
4
votes
3 answers

The Great Tree list recursion program

I faced an interesting problem called as the Great Tree-List Problem. The Problem is as follows : In the ordered binary tree, each node contains a single data element and "small" and "large" pointers to sub-trees .All the nodes in the "small"…
poorvank
  • 7,210
  • 17
  • 54
  • 102
4
votes
4 answers

Test if single linked list is circular by traversing it only once

I am a fresher and I was asked this question in a recent interview I gave. The question was --- By traversing each element of linked list just once find if the single linked list is circular at any point. To this I answered that we will store…
user1589754
  • 627
  • 2
  • 7
  • 18
4
votes
2 answers

Lazy generation of pairs of adjacent elements in a "circular list"

To check for ray-triangle collisions, we can first see if the ray collides with the triangle's plane. If it does, we then check if the intersection point is on the same side for all triangle sides. If true, this means that the point is inside the…
CanisLupus
  • 574
  • 5
  • 15
4
votes
2 answers

Pointing dereference inside a struct error

i have a function to create a circular list, i am having issues compiling, not sure if it is syntax, appreciate if someone can help. void CreateCircularList(struct node** listRef, struct node** tailRef) { Push(&*listRef, "String…
jelipito
  • 171
  • 1
  • 2
  • 12
3
votes
2 answers

Deleting all occurrences in a circular linked list. (java)

I want to implement a method that deletes all occurences of a certain value given as argument. I created 2 temporary elements and referenced them to the head and I will be browsing the list using them. I was able to write a whole code but I'm not…
Parasite
  • 37
  • 6
3
votes
1 answer

Reassigning positions in directional (circular) data using R

I have buckets arranged circularly (labelled pos 1 - 6). A monkey stands at the center and randomly throw stones in each bucket (inf) in three independent trials (sets). The goal here is to first identify the highest number of stones thrown in the…
3
votes
1 answer

Is this linked list implemented circularly?

This is my first post on here! I am a CS student, so I'm still learning. If you have any advice or pointers (haha..!) to give as far as structuring my code or general practice, I'd appreciate any feedback! I was given an assignment to re-implement…
Noah
  • 33
  • 5
3
votes
2 answers

Python: creating a class that could be iterated circularly

I want to create, in Python, a class behaving like a list but that could be iterated circularly use case example: myc = SimpleCircle() print(len(myc)) j = iter(myc) for i in range (0, 5): print(next(j)) it will print a b c d a the code I…
arzak
  • 33
  • 3
3
votes
2 answers

Overriding Iterator in circular array

I am writing my own Deque class and I need to override iterator. Example: Say the array is [3,4,5,null,null,null,1,2] where 1 is the front and 5 is the end. I would need to be able to use the iterator to start at 1 and end at after 5. Here is my…
3
votes
1 answer

Reducing a circular list in Common Lisp

I've been playing around with circular list in Common-lisp (SBCL) and encountered the following problem when trying to call REDUCE on such a list. First, we create a list: CL-USER> (defvar *foo* (list 1 1 1 1)) *foo* Of course, now we can…
jobach
  • 95
  • 7
3
votes
2 answers

Problems with circular singly linked list iterator

I am trying to make an iterator for my circular singly linked list, but I don't undertand how to implement the next() and hasNext() methods. I suspect that I need to either 1) have additional fields in the linked list class or the iterator class, or…
3
votes
2 answers

How to launch application on swipe in corners of android home screen or it may be any screen like lazy swipe

I am developing an app like Lazy Swipe how to launch the app like this from bottom/top corners of screen and how to implement circular scrolling .
Suren
  • 49
  • 1
  • 8
3
votes
6 answers

Java Method equals circular list

Here is the code for my Element class: public class Element { Element next; Element previous; T info; } ... and for CircularList: public class CircularList { Element first=null; public void add(Element e){ …
3
votes
2 answers

Circular linked list in javascript

I am trying to implement circular linked list in javascript. I just want to know is it the right way to implement this in javascript? Are there any memory leaks or infinite object creation? function LinkedList() { this.Node = null; …
sudhir
  • 147
  • 1
  • 3
  • 12
1 2
3
22 23