//{ /** * Sorts the array of comparable objects. */ protected function doSort() { for ($i = 1; $i < $this->n; ++$i) { for ($j = $i; $j > 0 && gt($this->array[$j - 1], $this->array[$j]); --$j) { $this->swap($j, $j - 1); } } } //}>a /** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("StraightInsertionSorter main program.\n"); $status = 0; $sorter = new StraightInsertionSorter(); AbstractSorter::test($sorter, 100, 123); return $status; } } if (realpath($argv[0]) == realpath(__FILE__)) { exit(StraightInsertionSorter::main(array_slice($argv, 1))); }
/** * Sorts the array to which the array field refers. * Calls the recursive quicksort method to do the actual sort. * Since the recursive quicksort method stops short of finishing the sort, * this method uses a StraightInsertionSorter to finish the job. */ protected function doSort() { $this->sortSlice(0, $this->n - 1); $sorter = new StraightInsertionSorter(); $sorter->sort($this->array); }