I'm trying to understand optionals and traversing the list. the code is not complete here. I stopped where I am puzzled. I will continue to flesh out the code, asking questions along the way.
thanks everyone. my question is at the bottom.
/* singly linked list */
import Foundation
public class Node {
var value : String
var next: Node?
init(value:String) {
self.value = value
}
} // class Node
/********** linked list class *************/
public class LinkedList {
var head: Node?
var tail: Node?
public var isEmpty: Bool {
return head == nil
}
public var first: Node? {
return head
}
public func append(value: String) {
let newNode = Node(value: value)
let theValue = head?.value
print(theValue!)
}
}// end public func append(...)
}
/* driver so far */
let l = LinkedList()
l.append(value: "asdf")
/****************
my question is about the print(theValue!) statement. why must the ! be uses? why could I not use let theValue = head?.value . or, why not let theValue = head?.head!**
thanks everyone. my question is at the bottom.
/* singly linked list */
import Foundation
public class Node {
var value : String
var next: Node?
init(value:String) {
self.value = value
}
} // class Node
/********** linked list class *************/
public class LinkedList {
var head: Node?
var tail: Node?
public var isEmpty: Bool {
return head == nil
}
public var first: Node? {
return head
}
Code Block public var last: Node? { return tail }
public func append(value: String) {
let newNode = Node(value: value)
Code Block if isEmpty {
head = newNodelet theValue = head?.value
print(theValue!)
}
}// end public func append(...)
}
/* driver so far */
let l = LinkedList()
l.append(value: "asdf")
/****************
my question is about the print(theValue!) statement. why must the ! be uses? why could I not use let theValue = head?.value . or, why not let theValue = head?.head!**
*****************/