shellsort using php

<?
// function shellsort($elements,$length)
//  {

$elements = array(2,3,4,5,1,8,11,0);
$length = count($elements);
     $k=0;
     $gap[0]=(int) ($length / 2);
     while($gap[$k]>1)
     {
         $k++;
         $gap[$k]=(int)($gap[$k-1]/2);
     }//end while

     for($i=0;$i<=$k;$i++)
     {
     $step=$gap[$i];
         for($j=$step;$j=0 && $temp<$elements[$p])
             {
                 $elements[$p+$step]=$elements[$p];
                 $p=$p-$step;
             }//end while
             $elements[$p+$step]=$temp;
         }//endfor j
     }//endfor i
//     return $elements;

print_r($elements);
//  }// end function

?>

http://www.go4expert.com/forums/showthread.php?t=1255

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s