1234567891011121314151617181920212223242526272829 |
- #!/usr/bin/ruby
- #
- ## https://rosettacode.org/wiki/Singly-linked_list/Element_insertion
- #
- func insert_after(a,b) {
- b{:next} = a{:next};
- a{:next} = b;
- }
-
- var B = :(
- data => 3,
- next => nil, # not a circular list
- );
- var A = :(
- data => 1,
- next => B,
- );
- var C = :(
- data => 2,
- );
-
- insert_after(A, C);
- say A;
- say B;
- say C;
|