2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,36 +1,38 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict ;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub orderlists {
|
||||
my $firstlist = shift ;
|
||||
my $secondlist = shift ;
|
||||
my $first = shift @{$firstlist } if @{$firstlist} ;
|
||||
my $second ;
|
||||
#keep stripping elements from the first list as long as there are any
|
||||
#or until the second list is used up!
|
||||
while ( @{$firstlist} ) {
|
||||
if ( @{$secondlist} ) { #second list is not used up yet!
|
||||
$second = shift @{$secondlist} ;
|
||||
if ( $first < $second ) {
|
||||
return 1 ;
|
||||
}
|
||||
if ( $first > $second ) {
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
else { #second list used up, defined to return false
|
||||
return 0 ;
|
||||
}
|
||||
$first = shift @{$firstlist} ;
|
||||
}
|
||||
return 0 ; #in all remaining cases return false
|
||||
my ($firstlist, $secondlist) = @_;
|
||||
|
||||
my ($first, $second);
|
||||
while (@{$firstlist}) {
|
||||
$first = shift @{$firstlist};
|
||||
if (@{$secondlist}) {
|
||||
$second = shift @{$secondlist};
|
||||
if ($first < $second) {
|
||||
return 1;
|
||||
}
|
||||
if ($first > $second) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@{$secondlist} ? 1 : 0;
|
||||
}
|
||||
|
||||
my @firstnumbers = ( 43 , 33 , 2 ) ;
|
||||
my @secondnumbers = ( 45 ) ;
|
||||
if ( orderlists( \@firstnumbers , \@secondnumbers ) ) {
|
||||
print "The first list comes before the second list!\n" ;
|
||||
}
|
||||
else {
|
||||
print "The first list does not come before the second list!\n" ;
|
||||
foreach my $pair (
|
||||
[[1, 2, 4], [1, 2, 4]],
|
||||
[[1, 2, 4], [1, 2, ]],
|
||||
[[1, 2, ], [1, 2, 4]],
|
||||
[[55,53,1], [55,62,83]],
|
||||
[[20,40,51],[20,17,78,34]],
|
||||
) {
|
||||
my $first = $pair->[0];
|
||||
my $second = $pair->[1];
|
||||
my $before = orderlists([@$first], [@$second]) ? 'true' : 'false';
|
||||
print "(@$first) comes before (@$second) : $before\n";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue