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
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!!
Bubble sort has no practical applications other than that it is often cited as an example of how not to write an algorithm. Insert sort is the best algorithm for sorting small lists of items and is often used in conjunction with quick sort to sort larger lists. Like insert sort, bubble sort is simple to implement and is a stable sort (equal items remain in the same order they were input). However, insert sort uses copy or move operations rather than swaps (which is actually three operations per swap) and is therefore quicker. The only time a bubble sort will work quicker than insert sort is when the array is already sorted, which renders the entire algorithm redundant. A modified algorithm that specifically tests if an array is sorted or not would be more efficient than a single-pass bubble sort.
You cannot sort arrays by other arrays; that wouldn't make sense, anyway.
The bubble sort algorithm can be applied to an array of characters. Every character can be translated to an integer equivalent via the ascii table