HOME

The Raku or Perl 6 Project

Introduction

Add something here ...


~kc4zvw:

  

Notes

Add something here ...

Header 2

Add something here ...


  

Header 3

Add something here ...

The 'Shellsort' Algorithm

Add something here ...


sub shell_sort ( @a is copy ) {
    loop ( my $gap = (@a/2).round; $gap > 0; $gap = ( $gap * 5 / 11 ).round ) {
        for $gap .. @a.end -> $i {
            my $temp = @a[$i];

            my $j;
            loop ( $j = $i; $j >= $gap; $j -= $gap ) {
                my $v = @a[$j - $gap];
                last if $v i<= $temp;
                @a[$j] = $v;
            }

            @a[$j] = $temp;
        }
    }
    return @a;
}
my @data = 22, 7, 2, -5, 8, 4;
say 'input  = ' ~ @data;
say 'output = ' ~ @data.&shell_sort;

  

Add something here ...

  input  = 22 7 2 -5 8 4
  output = -5 2 4 7 8 22
  


Miscellaneous

Add something here ...

  1. Links ...
  2. Links ...
  3. Links ...





Revised: Thursday, March 07, 2024 at 14:11:06 PM (EST)