Home > php教程 > php手册 > body text

php二维数组快速排序算法

WBOY
Release: 2016-06-06 19:53:08
Original
1283 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 二维数组排序算法与一维数组排序算法基本理论都是一样,都是通过比较把小的值放在左变的数组里,大的值放在右边的数组里在分别递归。 ?php class Bubble { private function __construct() { } pri

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  二维数组排序算法与一维数组排序算法基本理论都是一样,都是通过比较把小的值放在左变的数组里,大的值放在右边的数组里在分别递归。

  

  class Bubble {

  private function __construct() {

  }

  private static function sortt($data) {

  if (count ( $data )

  return $data;

  }

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

  $leftarray = array ();

  $rightarray = array ();

  for($i = 1; $i

  if ($data [$i]['score']

  $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));

php二维数组快速排序算法

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template