Created
July 30, 2019 06:17
-
-
Save tifoaudii/546cfffe004308f977463e9ad0e3fc39 to your computer and use it in GitHub Desktop.
Create a class represent a Node object that consist of value and next reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node<Value> { | |
var value: Value | |
var next: Node<Value>? | |
init(value: Value, next: Node<Value>? = nil ) { | |
self.value = value | |
self.next = next | |
} | |
} | |
extension Node: CustomStringConvertible { | |
var description: String { | |
guard let next = next else { | |
return "\(value)" | |
} | |
return "\(value) ->" + "\(next)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment