- or download this
sub insert_after {
my ($previous, $val) = @_;
...
my ($previous, $val) = @_;
return insert_after($previous->{prev}, $val);
}
- or download this
sub display {
my $curr = shift;
...
}
print "\n";
}
- or download this
my $head = {data => 0, prev => undef, next => undef};
my $previous = $head;
...
my $new_node = insert_after ($head, 0.5);
$new_node = insert_before ($new_node->{next}, 0.7);
display($head);
- or download this
$ perl doubly_linked.pl
Current: 0 Previous: Next: 1
...
Current: 3 Previous: 2 Next: 4
Current: 4 Previous: 3 Next: 5
- or download this
my $head = {data => 0, prev => undef, next => undef};
my $tail = $head;
...
chomp;
$tail = insert_after($tail, $_);
}
- or download this
#!/usr/bin/perl
...
$new_node = insert_before ($tail, 4.5);
display($head);
- or download this
$ perl doubly_linked.pl
...
Current: 3 Previous: 2 Next: 4
Current: 4 Previous: 3 Next: 4.5
Current: 4.5 Previous: 4 Next: 5