Guest User

Untitled

a guest
May 18th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. class Node(T)
  2. @val: T
  3. @next: Node(T)?
  4.  
  5. def initialize(@val)
  6. @next = nil
  7. end
  8.  
  9. property :val, :next
  10. end
  11.  
  12. class LinkedList(T)
  13. @head: Node(T)?
  14. @tail: Node(T)?
  15.  
  16. def push(val)
  17. node = Node(T).new val
  18.  
  19. if @tail
  20. @tail.next = node
  21. @tail = node
  22. else
  23. @head = node
  24. @tail = node
  25. end
  26. end
  27. end
  28.  
  29. ll = LinkedList(String).new
  30. ll.push "Hello"
  31. ll.push "World"
Add Comment
Please, Sign In to add comment