Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node(T)
- @val: T
- @next: Node(T)?
- def initialize(@val)
- @next = nil
- end
- property :val, :next
- end
- class LinkedList(T)
- @head: Node(T)?
- @tail: Node(T)?
- def push(val)
- node = Node(T).new val
- if @tail
- @tail.next = node
- @tail = node
- else
- @head = node
- @tail = node
- end
- end
- end
- ll = LinkedList(String).new
- ll.push "Hello"
- ll.push "World"
Add Comment
Please, Sign In to add comment