When we learn programming, we know that sorting methods include bubble sorting, quick sorting, selection sorting, etc., and the simultaneous sorting method Divided into two categories internal and external.
Sort method of array
Divided into two categories:
1. Internal (memory) sorting
2. External sorting (the amount of data is too large to be stored in the memory, so external sorting is required
Storage)
----------------
Sorting is a basic skill for a programmer
1: Internal sorting
(1) Commutative sorting
1. Bubble method
The default transfer of arrays is value transfer, not address transfer
We will talk about object types later. The default transfer of objects is address transfer
//Optimize, encapsulate the bubble sorting method into a function to facilitate future use
The code is as follows
|
Copy code
|
||||
function bubbleSort(&$myarr){ $temp=0;//Define an intermediate variable
for($i=0;$i +1]){ $temp=$myarr[$j]; |
$myarr[$j]=
}
3. Selection sorting method The code is as followsCopy code
|
function selectSort(&$myarr){
$temp=0;
for($i=0;$i | |