Advertisement
HXXXXJ

Print linked node

Apr 11th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.38 KB | None | 0 0
  1.  
  2. class Node{
  3.     var next : Node?
  4.     var val : Int
  5.     init(_ val : Int) {
  6.         self.val = val
  7.     }
  8. }
  9.  
  10. func printNode(_ root: Node?) {
  11.     guard let root = root else {
  12.         return
  13.     }
  14.     printNode(root.next)
  15.     print(root.val)
  16. }
  17.  
  18.  
  19.  
  20. print()
  21.  
  22. let n1 = Node(1)
  23. let n2 = Node(2)
  24. let n3 = Node(3)
  25. let n4 = Node(4)
  26.  
  27. n1.next = n2
  28. n2.next = n3
  29. n3.next = n4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement