Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites
Part III: ALGORITHMS An algorithm is a recipe for solving a problem. This section discusses broad problems in computer science a ...
Chapter 15. SORTING, SEARCHING, AND RANDOM NUMBERS Sorting Bubble Sort.......................................................... ...
take several forms but always involves comparing two elements with a set of rules for ordering. The result of the comparison det ...
Listing 15.1 Bubble Sort ...
...
...
It's easy to see that the bubble sort is very inefficient, but if you ran the example in Listing 15.1, you probably didn't get t ...
$pivot_point = intval(($left + $right)/2); $pivot = $input_array[$pivot_point]; do { while(($input_array[$left] < $pivot) AND ...
//print array print("Unsorted\n"); print(""); print_r($data); print("\n"); //sort array Quicksort(&$data, 0, count($data)-1) ...
Two other two sort functions, asort and arsort, work in a slightly different way. They preserve the relationship between the ind ...
...
Here I've used reset to put the internal array pointer at the first element. I then get each following element with the next fun ...
Listing 15.5 Using the asort Function ...
...
The last sorting function I want to discuss in this section is ksort. This function sorts an array on the values of the indices. ...
...
...
The ksort function is perhaps most useful in situations where you have an associative array and you don't have complete control ...
...
...
«
22
23
24
25
26
27
28
29
30
31
»
Free download pdf