Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
my @l = ($A, $B);
|
||||
push @l, $C, splice @l, 1;
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
sub insert_after {
|
||||
# first argument: node to insert after
|
||||
# second argument: node to insert
|
||||
$_[1]{next} = $_[0]{next};
|
||||
$_[0]{next} = $_[1];
|
||||
}
|
||||
|
||||
my %B = (
|
||||
data => 3,
|
||||
next => undef, # not a circular list
|
||||
);
|
||||
my %A = (
|
||||
data => 1,
|
||||
next => \%B,
|
||||
);
|
||||
my %C = (
|
||||
data => 2,
|
||||
);
|
||||
insert_after \%A, \%C;
|
||||
|
|
@ -0,0 +1 @@
|
|||
insert_after \%A, { data => 2 };
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
sub insert_after {
|
||||
my $node = $_[0];
|
||||
my $next = $node->{next};
|
||||
shift;
|
||||
while (defined $_[0]) {
|
||||
$node->{next} = $_[0];
|
||||
$node = $node->{next};
|
||||
shift;
|
||||
}
|
||||
$node->{next} = $next;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my %list = ( data => 'A' );
|
||||
insert_after \%list, { data => 'B' }, { data => 'C' };
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
my $list2;
|
||||
|
||||
# create a new list ('A'. 'B', 'C') and store it in $list2
|
||||
insert_after $list2 = { data => 'A' }, { data => 'B' }, { data => 'C' };
|
||||
|
||||
# append two new nodes ('D', 'E') after the first element
|
||||
insert_after $list2, { data => 'A2' }, { data => 'A3' };
|
||||
|
||||
# append new nodes ('A2a', 'A2b') after the second element (which now is 'A2')
|
||||
insert_after $list2->{next}, { data => 'A2a' }, { data => 'A2b' };
|
||||
Loading…
Add table
Add a link
Reference in a new issue