Home  >  Article  >  Backend Development  >  PHP quick sort problem

PHP quick sort problem

WBOY
WBOYOriginal
2016-09-27 14:18:061059browse

As shown in the picture: PHP quick method, two writing methods in the loop, the above one is OK, the following one will report errors;

PHP quick sort problem

Error screenshot:

PHP quick sort problem

Reply content:

As shown in the picture: PHP quick method, two writing methods in the loop, the above one is OK, the following one will report errors;

PHP quick sort problem

Error screenshot:

PHP quick sort problem

Did you think

<code>if ($v > $mid) {
    $rightArr[] = $v;
}
if ($v < $mid) {
    $leftArr[] = $v;
}</code>

and

<code>if ($v < $mid) {
    $leftArr[] = $v;
} else {
    $rightArr[] = $v;
}</code>

Does it mean the same thing?

Don’t you consider the situation where $v == $mid?

Statement:
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