blob: f67014447f647233cb67b2cc4c05550230a400ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use strict;
use warnings;
use feature qw/say/;
use Data::Dumper;
sub create_linked_list {
my $input = shift;
my $L;
for my $val (reverse split / /, $input) {
my $pt = { value => $val, next => $L };
$L = $pt;
}
return $L;
}
my $k = shift;
my $list_str = shift // "1 4 3 2 5 2";
my $list = create_linked_list $list_str;
# say Dumper $list;
my (@before, @after);
while (1) {
last unless defined $list->{value};
my $temp = $list->{value};
if ($temp < $k) {
push @before, $temp;
} else {
push @after, $temp;
}
$list = $list->{next}
}
say join " → ", @before, @after;
|