/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on succes; non-zero on failure. */ public static function main($args, $arg0) { //printf("Demonstration program number 9.\n"); $status = 0; if (count($args) != 3) { printf("usage: %s size seed mask\n", $arg0); $status = 1; } else { $n = intval($args[0]); $seed = intval($args[1]); $mask = intval($args[2]); if ($mask & 4 != 0) { AbstractSorter::test(new StraightInsertionSorter(), $n, $seed, $mask); AbstractSorter::test(new BinaryInsertionSorter(), $n, $seed, $mask); AbstractSorter::test(new BubbleSorter(), $n, $seed, $mask); AbstractSorter::test(new StraightSelectionSorter(), $n, $seed, $mask); } if ($mask & 2 != 0) { AbstractSorter::test(new HeapSorter(), $n, $seed, $mask); AbstractSorter::test(new MedianOfThreeQuickSorter(), $n, $seed, $mask); AbstractSorter::test(new TwoWayMergeSorter(), $n, $seed, $mask); } if ($mask & 1 != 0) { AbstractSorter::test(new BucketSorter(1024), $n, $seed, $mask, 1024); AbstractSorter::test(new RadixSorter(), $n, $seed, $mask); } } return $status; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("BinaryInsertionSorter main program.\n"); $status = 0; $sorter = new BinaryInsertionSorter(); AbstractSorter::test($sorter, 100, 123); return $status; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("StraightSelectionSorter main program.\n"); $status = 0; $sorter = new StraightSelectionSorter(); AbstractSorter::test($sorter, 100, 123); return $status; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("MedianOfThreeQuickSorter main program.\n"); $status = 0; $sorter = new MedianOfThreeQuickSorter(); AbstractSorter::test($sorter, 1000, 123); return $status; }
} $timer = new Timer(); $timer->start(); $sorter->sort($data); $timer->stop(); $datum = sprintf("%s %d %d %f", $sorter->getClass()->getName(), $n, $seed, $timer->getElapsedTime()); fprintf(STDOUT, "%s\n", $datum); fprintf(STDERR, "%s\n", $datum); for ($i = 1; $i < $n; ++$i) { if ($data[$i] < $data[$i - 1]) { printf("FAILED\n"); break; } } } /** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("AbstractSorter main program.\n"); $status = 0; return $status; } } if (realpath($argv[0]) == realpath(__FILE__)) { exit(AbstractSorter::main(array_slice($argv, 1))); }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("TwoWayMergeSorter main program.\n"); $status = 0; $sorter = new TwoWayMergeSorter(); AbstractSorter::test($sorter, 1000, 123); return $status; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("BucketSorter main program.\n"); $status = 0; $sorter = new BucketSorter(1000); AbstractSorter::test($sorter, 10000, 123, 100); return $status; }
/** * Destructor. */ public function __destruct() { parent::__destruct(); }