Help for this page

Select Code to Download


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