Skip to content

Instantly share code, notes, and snippets.

@tobyink

tobyink/linked-lists.pl

Last active Sep 25, 2020
Embed
What would you like to do?
Linked lists, Zydeco example
package SLL {
use Zydeco;
class Node {
has value ( type => Int );
has nextnode ( type => Maybe[Object] );
method printvalue () {
print $self->value, " ";
}
method go_next = $self->nextnode;
factory new_node ( Int $value, Object $next? ) {
return $class->new(
value => $value,
nextnode => $next
);
}
}
}
my $node_a = SLL->new_node(30);
my $node_b = SLL->new_node(40, $node_a);
my $node_c = SLL->new_node(70, $node_b);
my $node_head = SLL->new_node(0, $node_c);
my $node = $node_head;
while ( $node = $node->go_next ) {
$node->printvalue;
}
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.