/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { $status = 0; printf("4\n"); printf("sort\n"); printf("length\n"); printf("seed\n"); printf("time\n"); foreach (array("1", "57", "12345", "7252795", "3127") as $seed) { foreach (array("10", "250", "500", "750", "1000", "1250", "1500", "1750", "2000") as $length) { Demo9::main(array($length, $seed, "7"), $argv[0]); } foreach (array("3000", "4000", "5000", "6000", "7000", "8000", "9000", "10000") as $length) { Demo9::main(array($length, $seed, "3"), $argv[0]); } foreach (array("20000", "30000", "40000", "50000", "60000", "70000", "80000", "90000", "100000") as $length) { Demo9::main(array($length, $seed, "1"), $argv[0]); } } return $status; }
//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; } } if (realpath($argv[0]) == realpath(__FILE__)) { exit(Demo9::main(array_slice($argv, 1), $argv[0])); }