package LinkedListModule import Wurstunit public module LinkedListModule static thistype first = null static thistype last = null static int size = 0 thistype prev thistype next construct() size++ if size == 1 first = this prev = null else prev = last last.next = this first.prev = this next = null last = this static function getFirst() returns thistype return first function getNext() returns thistype return next function getPrev() returns thistype return prev function remove() size-- if this != first prev.next = next else first = next if this != last next.prev = prev else last = prev ondestroy remove() /** an iterator which iterates over all instances of this class */ static function iterator() returns Iterator return new Iterator() static class Iterator LinkedListModule.thistype current = first function hasNext() returns boolean return current != null function next() returns LinkedListModule.thistype let res = current current = current.next return res function close() destroy this class MyClass use LinkedListModule string str construct(string str) this.str = str function allToString() returns string string res = "" for x in MyClass res += x.str return res @test function test() let a = new MyClass("a") let b = new MyClass("b") let c = new MyClass("c") let d = new MyClass("d") assertTrue(allToString() == "abcd") destroy c assertTrue(allToString() == "abd") destroy d assertTrue(allToString() == "ab") destroy a assertTrue(allToString() == "b") destroy b assertTrue(allToString() == "") @test function testDestroy() new MyClass("a") let b = new MyClass("b") new MyClass("c") new MyClass("d") string s = "" for x in MyClass s += x.str if x == b destroy x assertTrue(s=="abcd") assertTrue(allToString() == "acd") for x in MyClass destroy x assertTrue(allToString() == "")