Skip to content

Commit

Permalink
use isDefined to replace nonEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Dec 14, 2018
1 parent 0f8c628 commit a61611a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scala/src/main/scala/ch06_linkedlist/SinglyLinkedList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SinglyLinkedList(var headOpt: Option[Node]) {
def findByValue(value: Int): Option[Node] = {
headOpt.flatMap(head => {
var node = head
while (!node.data.equals(value) && node.next.nonEmpty) {
while (!node.data.equals(value) && node.next.isDefined) {
node = node.next.get
}

Expand Down Expand Up @@ -56,7 +56,7 @@ class SinglyLinkedList(var headOpt: Option[Node]) {
case Some(head) =>
//need to start to find from head to current tail
var node = head
while (node.next.nonEmpty) {
while (node.next.isDefined) {
node = node.next.get
}
//now node is the tail as node.next is None
Expand Down Expand Up @@ -96,7 +96,7 @@ class SinglyLinkedList(var headOpt: Option[Node]) {
insertToHead(newNode)
}
var node = head
while (node.next.nonEmpty && !node.next.get.equals(existNode)) {
while (node.next.isDefined && !node.next.get.equals(existNode)) {
node = node.next.get
}

Expand Down Expand Up @@ -209,7 +209,7 @@ class SinglyLinkedList(var headOpt: Option[Node]) {
var node = head
val result = new StringBuilder

while (node.next.nonEmpty) {
while (node.next.isDefined) {
result.append(node.data)
node = node.next.get
}
Expand Down

0 comments on commit a61611a

Please sign in to comment.