Import std.collections.linked_list
std.collections.linked_list
A doubly linked list, which adds and removes values beside a node in constant time.
LinkedList<T>: values in a chain of nodes, each linked to the ones before and after it, so
adding or removing one beside a node takes the same time however many there are. A node is the
same object for as long as it's in the list, so code can keep one to add beside or remove when
it likes. Each node holds the one after it and, weakly, the one before, so the list makes no
cycles, and Clear and the list's end unlink every node, so a node kept elsewhere holds none of
the others.
std/collections/linked_list.fb
Types
LinkedListNode
class
Public Class LinkedListNode<T>
One value of a LinkedList, with the ones before and after it, which inserting and removing next to it go through.
Examples
Local list = LinkedList<Int>()
Local first = list.Add(1)
list.Add(2)
Expect(first.Next?.Value == 2 && first.Previous == Null)
first.Value = 10
Expect(list.ToArray() == [10, 2])std/collections/linked_list.fb, line 26
-
Its value.
-
The node after this one, or Null when it's the last or not in a list.
-
The node before this one, or Null when it's the first or not in a list.
-
The list it's in, or Null once it's removed.
LinkedList
class
@DebugElements Public Class LinkedList<T> Implements Iterable<T>, Cloneable, Defaultable
A doubly linked list, which inserts and removes anywhere it has a node without moving the rest.
Examples
Local list = LinkedList<String>()
Local b = list.Add("b")
list.AddFirst("a")
list.AddAfter(b, "c")
Expect(list.ToArray() == ["a", "b", "c"])
list.RemoveNode(b)
Expect(list.ToArray() == ["a", "c"])
Expect(b.List == Null)std/collections/linked_list.fb, line 69
-
How many values it holds.
-
The first node, or Null when the list is empty.
-
The last node, or Null when the list is empty.
-
The first value. Panics when the list is empty.
-
The last value. Panics when the list is empty.
-
The first value, or Null when the list is empty.
-
The last value, or Null when the list is empty.
-
Adds the
valueat the start, and gives its node. -
Adds the
valueat the end, and gives its node. -
The same as AddLast.
-
Adds each of the
valuesat the end, in order, all read first. -
@PanicsAtCaller Public Method AddBefore(node: LinkedListNode<T>, value: T): LinkedListNode<T>method #Adds the
valuejust beforenode, which has to be in this list, and gives its node. -
@PanicsAtCaller Public Method AddAfter(node: LinkedListNode<T>, value: T): LinkedListNode<T>method #Adds the
valuejust afternode, which has to be in this list, and gives its node. -
Takes
node, which has to be in this list, out of it. -
Takes out the first
valueequal tovalue, and tells whether there was one. -
Takes the first value out and gives it. Panics when the list is empty.
-
Takes the last value out and gives it. Panics when the list is empty.
-
Takes the first value out and gives it, or Null when the list is empty.
-
Takes the last value out and gives it, or Null when the list is empty.
-
The first node whose value is equal to
value, or Null. -
The last node whose value is equal to
value, or Null. -
Whether it holds
value. -
The first value that
testsays is the one, or Null. -
The last value that
testsays is the one, or Null. -
Takes every value out. Their nodes are no longer in a list.
-
The values, first to last, in a new array.
-
A new, empty LinkedList.
-
A new LinkedList with the same values, in nodes of its own.
-
The values, first to last. Setting a node's Value while going over them is fine, but adding or removing one panics.
LinkedListIterator
struct
Public Struct LinkedListIterator<T> Implements Iterator<T>
The values of a LinkedList, first to last, which a For loop goes over.
std/collections/linked_list.fb, line 363
-
The next value, from the first node to the last, or Null after it. Panics when the LinkedList changed since the loop began.
Extends
LinkedList
extend
Extend LinkedList<T> Implements Equatable
Compares LinkedLists with == and !=, where their values can be compared.
std/collections/linked_list.fb, line 385
-
Whether the two have equal values in the same order.
LinkedList
extend
Extend LinkedList<T> Implements Printable
Shows a LinkedList in a string, as its ToString writes it.
std/collections/linked_list.fb, line 404
-
Its values, first to last, as an array shows them: "[1, 2, 3]".
Report an issue with this page or with FutureBlitz on GitHub.