Here it is:
$array_size = 250;
// If you use v4.2.0 or lower uncomment this
// srand((double)microtime()*1000000);
// Generate $array_size random numbers to be sorted.
for($x = 0; $x < $array_size; $x++)
$ran[$x] = rand(0, 500);
/* The bubble sort method. If you don't know how it works it's very
* simple, values are switched one at a time for each element. */
for($x = 0; $x < $array_size; $x++) {
for($y = 0; $y < $array_size; $y++) {
if($ran[$x] < $ran[$y]) {
$hold = $ran[$x];
$ran[$x] = $ran[$y];
$ran[$y] = $hold;
}
}
}
for($x = 0; $x < $array_size; $x++)
print $ran[$x] . "<br>";
Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php
You cannot sort arrays by other arrays; that wouldn't make sense, anyway.
plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++
sort() will order the array by its values without preserving the keys. Use it when array is indexed numerically or when you do not care about the keys. asort() will also sort the array by its values, but it will preserve the key -> value association.
Usually <?php ... ?> or <? ... ?>
Bubble sort is also known as sinking sort.
PHP certification is received after doing some sort of PHP course, there are many out there to do. You can use them in your CV to help you get a job in PHP.
Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php
Yes, bubble sort is a stable sorting algorithm.
Selection sort is more efficient for small datasets compared to bubble sort.
ramesh
Bubble sort is an "in place" algorithm. Other than a temporary "switch" variable, no extra space is required.
bubbles
no
Binary sort and bubble sort are two.
You would sort the given elements of an array by a bubble sort or heap sort code!!
The running time of the bubble sort algorithm is O(n2), where n is the number of elements in the array being sorted.