Skip to content

Instantly share code, notes, and snippets.

@tifoaudii
Created July 30, 2019 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tifoaudii/7c51cf80d446e065d89167fdb3239cd5 to your computer and use it in GitHub Desktop.
Save tifoaudii/7c51cf80d446e065d89167fdb3239cd5 to your computer and use it in GitHub Desktop.
Create a linkedlist class that consist of more than one node objects
public struct Linkedlist<Value> {
public var head: Node<Value>?
public var tail: Node<Value>?
public var isEmpty: Bool {
return head == nil
}
init() {}
public mutating func push(_ value: Value) {
head = Node(value: value, next: head)
if tail == nil {
tail = head
}
}
}
extension Linkedlist: CustomStringConvertible {
public var description: String {
guard let head = head else {
return "empty data"
}
return "\(head)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment