Jump to content

Category talk:Wren-llist: Difference between revisions

→‎Source code: Added a 'nodes' iterator and changed a method name (swap -> exchange).
(→‎Source code: Bug fix.)
(→‎Source code: Added a 'nodes' iterator and changed a method name (swap -> exchange).)
Line 269:
 
// Exchanges the elements at indices 'i' and 'j' of the current instance.
swapexchange(i, j) {
var t = this[i]
this[i] = this[j]
Line 288:
var i = start
for (e in seq) {
if (e == d) return i
i = i + 1
}
return -1
Line 389:
// Returns true if this instance contains NONE of the values, false otherwise.
containsNone(ds) { !containsAny(ds) }
 
// Combines the elements of this instance plus those of another LinkedList object
// into a new LinkedList and returns it.
Line 409:
 
iteratorValue(iterator) { iterator.data }
 
// Iterates through the nodes of this instance and returns for each one
// a list containing the current and next data members.
nodes {
class N is Sequence {
construct new(head) {
_head = head
}
 
iterate(iterator) {
if (!iterator) {
return !_head ? false : _head
}
return iterator.next
}
 
iteratorValue(iterator) {
var n = iterator.next
var next = (n) ? n.data : null
return [iterator.data, next]
}
}
return N.new(_head)
}
 
// Prints the consecutive elements of the current instance to stdout
// separated by a single space and followed by a new line.
print() {
for (e in this) System.write("%(e) ")
System.print()
}
 
Line 703 ⟶ 727:
 
// Exchanges the elements at indices 'i' and 'j' of the current instance.
swapexchange(i, j) {
var t = this[i]
this[i] = this[j]
Line 900 ⟶ 924:
}
return R.new(_tail)
}
// Iterates through the nodes of this instance and returns for each one
// a list containing the previous, current and next data members.
nodes {
class N is Sequence {
construct new(head) {
_head = head
}
 
iterate(iterator) {
if (!iterator) {
return !_head ? false : _head
}
return iterator.next
}
 
iteratorValue(iterator) {
var p = iterator.prev
var prev = (p) ? p.data : null
var n = iterator.next
var next = (n) ? n.data : null
return [prev, iterator.data, next]
}
}
return N.new(_head)
}
 
// Prints the consecutive elements of the current instance to stdout
// separated by a single space and followed by a new line.
print() {
for (e in this) System.write("%(e) ")
System.print()
}
 
// As 'print' method but prints the elements in reverse.
rprint() {
for (e in this.reversed) System.write("%(e) ")
System.print()
}
 
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.