Php two-dimensional array quick Sorting Algorithm

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to enter the two-dimensional array Sorting Algorithm and one-dimensional array sorting algorithm. The basic theories are the same, we put small values in the left-changing array by comparison, and put large values in the right-side array for recursion respectively .? PhpclassBubble {privatefunction _ construct () {} pri

Welcome to the Linux community forum to interact with 2 million technical staff> the basic theories of the Two-dimensional array Sorting Algorithm and the one-dimensional array sorting algorithm are the same, by relatively placing small values in the left-changing array, the large values are placed in the right array and recursive respectively. ? Php class Bubble {private function _ construct () {} pri

Welcome to the Linux community forum and interact with 2 million technicians>

The basic theories of the Two-dimensional array Sorting Algorithm and the one-dimensional array sorting algorithm are the same. They both place small values in the left-changing array by comparison, and the large values in the right array by recursion respectively.

  

Class Bubble {

Private function _ construct (){

}

Private static function sortt ($ data ){

If (count ($ data) <= 1 ){

Return $ data;

}

$ Tem = $ data [0] ['score '];

$ Leftarray = array ();

$ Rightarray = array ();

For ($ I = 1; $ I <count ($ data); $ I ++ ){

If ($ data [$ I] ['score '] <= $ tem ){

$ Leftarray [] = $ data [$ I];

} Else {

$ Rightarray [] = $ data [$ I];

}

}

$ Leftarray = self: sortt ($ leftarray );

$ Rightarray = self: sortt ($ rightarray );

$ Sortarray = array_merge ($ leftarray, array ($ data [0]), $ rightarray );

Return $ sortarray;

}

Public static function main ($ data ){

$ Ardata = self: sortt ($ data );

Return $ ardata;

}

}

$ Arr = array (

Array ('sid '=> 1, 'score' => 76 ),

Array ('sid '=> 2, 'score' => 93 ),

Array ('sid '=> 3, 'score' => 68.5 ),

Array ('sid '=> 4, 'score' => 82.5 ),

Array ('sid '=> 5, 'score' => 60.5)

);

Print_r (Bubble: main ($ arr ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.