Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function select(list[1..n], k)
- for i from 1 to k
- maxIndex = i
- maxValue = list[i]
- for j from i+1 to n
- if list[j] > maxValue
- maxIndex = j
- maxValue = list[j]
- swap list[i] and list[maxIndex]
- return list[k]
- newarray[] = select(array, 1);
- newarray[] = select(array, 2);
- newarray[] = select(array, 3);
- function threeLargest($array){
- krsort($array, "SORT_NUMERIC");
- $return[0] = $array[0];
- $return[1] = $array[1];
- $return[2] = $array[2];
- return $return;
- }
Add Comment
Please, Sign In to add comment