Home > Backend Development > PHP Tutorial > PHP implements merge sort (merge sort)--analysis of algorithm principles

PHP implements merge sort (merge sort)--analysis of algorithm principles

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:13:26
Original
1066 people have browsed it

Merge sort: The time complexity is ~O(nlogn)--also known as Merge sort

The merge sort method is to merge two (or more) ordered lists into a new ordered list ,

That is, the sequence to be sorted is divided into several ordered subsequences, and then the ordered subsequences are merged into an overall ordered sequence.

<?php $arrStoreList = array(3,2,4,1,5);
$sort = new Merge_sort();
$sort->stableSort($arrStoreList, function ($a, $b) {    // function ($a, $b)匿名函数
            return $a require no action.
        if (count($array) 
Copy after login

Output result: Array ( [0] => 5 [1] => 4 [2] => 3 [3] => 2 [4] => 1)

Analysis of algorithm principles: The key is to understand the principle of recursive calls and their return functions

PHP implements merge sort (merge sort)--analysis of algorithm principles

The above introduces the implementation of merge sort (merge sort) in PHP - analysis of algorithm principles, including require aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template