Doubly-linked list implementation that implements all common list, stack and queue operations. Permits all elements (including null). Use the Typecasting package if you require lists of warcraft handles. LinkedLists should be generally used anywhere you need a list, because they are the most versatile and fast in common operations. If you need faster contains or access operations on big lists, use HashList. If you want to limit each element’s occurance to one, consider HashSet.
📖 Read the detailed guide for hand-written examples and background.
public class LinkedList<T>
Members:
construct(thistype base) Creates a new list by copying all elements from another list into itconstruct() Creates a new empty listadd(vararg T elems) Adds one or more elements to the end of the list (top of stack, beginning of queue)addAll(LinkedList<T> elems) Adds all elements from elems to the end of this listsplice(LinkedList<T> other) Adds all elements from the other list to the end of this list and removes them from the provided list.
It does not add/remove elements internally, only the internal pointers of the list nodes are re-pointed.
The other list will be empty, but not destroyed.
get(int index) returns T Returns the element at the specified indexindexOf(T t) returns int Returns the index of the specified element or -1 is it doesn’t existset(int index, T elem) Sets the element at the specified indexpush(T elem) Adds an element to the end of the list (top of stack, beginning of queue)getFirst() returns T Returns the first element in the listgetLast() returns T Returns the last element in the listdequeue() returns T Returns and removes the first added Element (FIFO)pop() returns T Returns and removes the last added Element (LIFO)peek() returns T Returns the lastly added Elementhas(T elem) returns boolean Returns whether the lists contains the specified elementremoveAt(int index) returns T Removes the element and it’s entry at the given indexremove(T elem) returns bool Removes the first occurence of t from this list. Returns true if an element was removed from the list.size() returns int gets the size of the list (java-compat wrapper)isEmpty() returns boolean checks whether this list is emptycopy() returns LinkedList<T> Returns a shallow copy of this liststaticItr() returns LLIterator<T> get the static iterator for this liststaticBackItr() returns LLBackIterator<T> get the static back iterator for this listiterator() returns LLIterator<T> get an iterator for this listbackiterator() returns LLBackIterator<T> get a backiterator for this listenqueue(T elem) adds an element to the beginning of the listaddtoStart(T elem) adds an element to the beginning of the listreplace(T whichElement, T newElement) returns boolean replaces the first occurence of ‘whichElement’ with ‘newElement’ returns true when an element has been replaced, false if ‘whichelement’ is not contained in the listremoveIf(LinkedListPredicate<T> predicate) Removes the element if the predicates returns trueforEach(LLItrClosure<T> itr) returns LinkedList<T> Executes the closure for each elementupdateAll(LinkedListUpdater<T> f) Updates all elementsshuffle() Performs a Fisher–Yates shuffle on this listgetRandomElement() returns T Returns a random element from this list or null, if emptyaddAt(T elem, int index) Adds the given element directly behind the element at the given indexsortWith(Comparator<T> comparator) Sorts the list according the the comparator using merge sortmap<Q>(MapClosure<T, Q> itr) returns LinkedList<Q> Returns the list obtained by applying the given closure to each element of the original listfilter(LinkedListPredicate<T> predicate) returns LinkedList<T> Returns a new list of the elements that satisfy the predicatefoldl<Q>(Q startValue, FoldClosure<T, Q> predicate) returns Q ‘Folds’ this list into a single value of type Q Example int-list sum: list.foldl<int>(0, (i, q) -> q + i)find(LinkedListPredicate<T> predicate) returns T Returns the first element that satisfies the predicate, or null if none presenttoString() returns string Prints the content of the listclear() Removes all elements from the listpublic class LLIterator<T>
Members:
construct(LinkedList<T> parent)construct(LinkedList<T> parent, bool destroyOnClose)reset()remove() returns T Removes from the list the last element that was returned by next() (optional operation). This call can only be made once per call to nextmodify(T newval) Modifies the last element that was returned by next() (optional operation).hasNext() returns booleannext() returns Tlookahead() returns Tprevious() returns TaddBefore(T elem) Adds an element before the currently iterated elementclose()public class LLBackIterator<T>
Members:
construct(LinkedList<T> parent, bool destroyOnClose)construct(LinkedList<T> parent)reset()modify(T newval) Modifies the last element that was returned by next() (optional operation).hasNext() returns booleannext() returns Tlookahead() returns TaddBefore(T elem) Adds an element before the currently iterated elementclose()public interface LinkedListPredicate<T>
Members:
isTrueFor(T t) returns booleanpublic interface LLItrClosure<T>
Members:
run(T t)public interface LinkedListUpdater<T>
Members:
update(T t) returns Tpublic interface MapClosure<T, Q>
Members:
run(T t) returns Qpublic interface FoldClosure<T, Q>
Members:
run(T t, Q q) returns Qpublic interface Comparator<T>
Members:
compare(T o1, T o2) returns intpublic function asList<T>(vararg T ts) returns LinkedList<T>
public function LinkedList<real>.sort()
public function LinkedList<int>.sort()
public function LinkedList<string>.sort()
public function group.asList() returns LinkedList<unit>
public function LinkedList<string>.joinBy(string separator) returns string
Joins elements from a string list into one string using a separator
public function LinkedList<T>.joinBy<T>(ToStringClosure<T> cls, string separator) returns string
public function LinkedList<string>.join() returns string
Joins elements from a string list into one string