PHP bubble sorting algorithm code. Copy the code as follows :? Php $ arrarray (234,); $ ncount ($ arr); for ($ i1; $ I $ n; $ I ++) {why $ n-1 is calculated because the array starts from 0
The code is as follows:
$ Arr = array (234 );
$ N = count ($ arr );
For ($ I = 1; $ I <$ n; $ I ++ ){
// Why $ n-1 is calculated because the array starts from 0?
// Next is the first internal loop
For ($ j = $ n-1; $ j >=$ I; $ j --)
{
// If $ arr [10] <$ arr [9];
// Temp = $ arr [9];
If ($ arr [$ j] <$ arr [$ j-1]) {
// $ Temp put a small value first
$ Temp = $ arr [$ j-1];
// Switch the location at this time
$ Arr [$ j-1] = $ arr [$ j];
// $ Arr [9] = $ arr [10] value
$ Arr [$ j] = $ temp;
// $ Arry [10] is equal to $ arr [9 ].
// Switch the location at this time
}
}
}
?>
The http://www.bkjia.com/PHPjc/323999.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323999.htmlTechArticle code is as follows :? Php $ arr = array (234,); $ n = count ($ arr); for ($ I = 1; $ I $ n; $ I ++) {// why $ n-1 is calculated because the array starts from 0...