Smallville7123
04/15/2019, 1:27 PMribesg
04/15/2019, 1:28 PMhasNext()
returning true
means that next()
will workSmallville7123
04/15/2019, 1:29 PMs.forEach { println("it = $it") }
does not print the last element if there is more than 1 element, and does not print anything at all if there is only 1 elementgildor
04/15/2019, 1:30 PMSmallville7123
04/15/2019, 1:30 PMfun main() {
val word = "ab"
println("word = " + word)
val s = stringToStack(word)
println("stringToStack = $s")
val i = s.iterator()
while (i.hasNext()) println("next = " + i.next())
s.forEach { println("it = $it") }
}
ribesg
04/15/2019, 1:31 PMstringToStack
gildor
04/15/2019, 1:31 PMSmallville7123
04/15/2019, 1:32 PMword = ab
stringToStack = [a, b]
next = a
it = a
gildor
04/15/2019, 1:33 PMSmallville7123
04/15/2019, 1:33 PMfun stringToStack(str: String): Stack<String> {
val deq = Stack<String>()
var i = 0
while (i < str.length) deq.addLast(str[i++].toString())
return deq
}
gildor
04/15/2019, 1:35 PMShawn A
04/15/2019, 1:35 PMgildor
04/15/2019, 1:36 PMSmallville7123
04/15/2019, 1:37 PMribesg
04/15/2019, 1:38 PMLinkedList
Smallville7123
04/15/2019, 1:39 PMmain
, stringToStack
, Stack
and LinkedList
ribesg
04/15/2019, 1:40 PMgildor
04/15/2019, 1:41 PMSmallville7123
04/15/2019, 1:43 PMReturns true if the iteration has more elements.
Returns the next element in the iteration.
for https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterator/next.htmlribesg
04/15/2019, 1:46 PMSmallville7123
04/15/2019, 1:48 PMtrue
means that next()
will work"ribesg
04/15/2019, 1:49 PMSmallville7123
04/15/2019, 1:49 PMnext
element, not the current
elementribesg
04/15/2019, 1:49 PMnext
meansSmallville7123
04/15/2019, 1:50 PMribesg
04/15/2019, 1:50 PMSmallville7123
04/15/2019, 1:53 PM/**
* Returns the next element in the iteration.
*/
override fun next(): T? {
node = node?.next
if (node != null) {
return node?.value
}
throw Exception("No Such Element")
}
thus return...word = ab
stringToStack = [a, b]
next = b
it = b
for fun main() {
val word = "ab"
println("word = " + word)
val s = stringToStack(word)
println("stringToStack = $s")
val i = s.iterator()
while (i.hasNext()) println("next = " + i.next())
s.forEach { println("it = $it") }
}
?gildor
04/15/2019, 1:55 PMwhich implies theThere is no such thing as "current" element in iterator, there is only "next" or nothingelement, not thenext
elementcurrent
ribesg
04/15/2019, 1:56 PMnext
was wrong I never said it was the only thing wrongSmallville7123
04/15/2019, 1:58 PMgildor
04/15/2019, 1:59 PMSmallville7123
04/15/2019, 1:59 PMoverride fun hasNext(): Boolean = node != null
override fun next(): T? {
val var0 = node?.value
node = node?.next
return var0
}
if (tokenList.peek() == null) {
try {
tokenList.pop()
} catch (e: java.util.NoSuchElementException) {
return null
}
}
tokenList
originally being of type ArrayDeque
ribesg
04/15/2019, 2:18 PMSmallville7123
04/15/2019, 2:20 PMThrows:
NoSuchElementException - if this deque is empty