Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.43 KB | None | 0 0
  1. class Node {
  2.     has Int $.data;
  3.     has Node $.next = Nil;
  4. }
  5.  
  6. class LinkedList {
  7.     has Node $.head;
  8.  
  9.     method concat_list_str(Node $curr) {
  10.     if !$curr {
  11.         "";
  12.     } elsif !$curr.next {
  13.         $curr.data.Str
  14.     } else {
  15.       $curr.data.Str ~ "," ~ .concat_list_str($curr.next)
  16.     }
  17.     }
  18.  
  19.     method gist() {
  20.     "[" ~ .concat_list_str($.head) ~ "]"
  21.     }
  22. }
  23.  
  24. my $list = LinkedList.new(head => Node.new(data => 1));
  25. say $list;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement