@@ -88,6 +88,10 @@ public class LinkedList<T>
8888 function getFirst() returns T
8989 return dummy.next.elem
9090
91+ /** Returns the last element in the list */
92+ function getLast() returns T
93+ return dummy.prev.elem
94+
9195 /** Returns and removes the first added Element (FIFO) */
9296 function dequeue() returns T
9397 let top = dummy.next
@@ -108,7 +112,7 @@ public class LinkedList<T>
108112
109113 /** Returns the lastly added Element */
110114 function peek() returns T
111- return dummy.prev.elem
115+ return getLast()
112116
113117 /** Returns whether the lists contains the specified element */
114118 @deprecated("Use .has instead") function contains(T elem) returns boolean
@@ -175,7 +179,7 @@ public class LinkedList<T>
175179 /** get the static back iterator for this list */
176180 function staticBackItr() returns LLBackIterator<T>
177181 if staticBackItr == null
178- staticBackItr = new LLBackIterator<T>(dummy , false)
182+ staticBackItr = new LLBackIterator<T>(this , false)
179183 staticBackItr.reset()
180184 return staticBackItr
181185
@@ -185,11 +189,11 @@ public class LinkedList<T>
185189
186190 /** get a backiterator for this list */
187191 function backiterator() returns LLBackIterator<T>
188- return new LLBackIterator(dummy )
192+ return new LLBackIterator(this )
189193
190194 /** adds an element to the beginning of the list */
191195 function enqueue(T elem)
192- addtoStart (elem)
196+ add (elem)
193197
194198 /** adds an element to the beginning of the list */
195199 function addtoStart(T elem)
@@ -491,6 +495,9 @@ public class LLIterator<T>
491495 retVal = current.next.elem
492496 return retVal
493497
498+ function previous() returns T
499+ return current.prev.elem
500+
494501 /** Adds an element before the currently iterated element */
495502 function addBefore(T elem)
496503 let entry = new LLEntry<T>(elem, current.prev, current)
@@ -505,18 +512,20 @@ public class LLIterator<T>
505512public class LLBackIterator<T>
506513 LLEntry<T> dummy
507514 LLEntry<T> current
515+ LinkedList<T> parent
508516 protected bool destroyOnClose = true
509517
510- construct(LLEntry <T> dummy , bool destroyOnClose)
511- this.dummy = dummy
518+ construct(LinkedList <T> parent , bool destroyOnClose)
519+ this.parent = parent
512520 reset()
513521 this.destroyOnClose = destroyOnClose
514522
515- construct(LLEntry <T> dummy )
516- this.dummy = dummy
523+ construct(LinkedList <T> parent )
524+ this.parent = parent
517525 reset()
518526
519527 function reset()
528+ this.dummy = parent.getDummy()
520529 this.current = dummy
521530
522531 /** Modifies the last element that was returned by next() (optional operation). */
@@ -537,6 +546,13 @@ public class LLBackIterator<T>
537546 retVal = current.prev.elem
538547 return retVal
539548
549+ /** Adds an element before the currently iterated element */
550+ function addBefore(T elem)
551+ let entry = new LLEntry<T>(elem, current.prev, current)
552+ current.prev.next = entry
553+ current.prev = entry
554+ parent.size++
555+
540556 function close()
541557 if destroyOnClose
542558 destroy this
@@ -567,6 +583,10 @@ constant Comparator<int> intComparator = (i1, i2) -> i1 - i2
567583public function LinkedList<int>.sort()
568584 this.sortWith(intComparator)
569585
586+ constant Comparator<string> stringComparator = (s1, s2) -> stringCompare(s1, s2)
587+ public function LinkedList<string>.sort()
588+ this.sortWith(stringComparator)
589+
570590public function group.asList() returns LinkedList<unit>
571591 let result = new LinkedList<unit>()
572592 this.forEachFrom() u ->
@@ -607,4 +627,4 @@ public function LinkedList<string>.join() returns string
607627 return this.joinBy("")
608628
609629init
610- realToIndex(0.)
630+ realToIndex(0.)
0 commit comments