singly-linked_list_element_insertion.sf 356 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Singly-linked_list/Element_insertion
  4. #
  5. func insert_after(a,b) {
  6. b{:next} = a{:next};
  7. a{:next} = b;
  8. }
  9.  
  10. var B = :(
  11. data => 3,
  12. next => nil, # not a circular list
  13. );
  14. var A = :(
  15. data => 1,
  16. next => B,
  17. );
  18. var C = :(
  19. data => 2,
  20. );
  21.  
  22. insert_after(A, C);
  23. say A;
  24. say B;
  25. say C;