Home > Backend Development > PHP Tutorial > Such profound knowledge~ Sorting can be achieved using only two stacks

Such profound knowledge~ Sorting can be achieved using only two stacks

WBOY
Release: 2016-07-29 09:05:14
Original
1662 people have browsed it
$stackA = range(1,9);
shuffle($stackA);
print_r($stackA);
$stackB = array();
while(count($stackA)){
    $tmpA = array_shift($stackA);
    while(count($stackB)){
        $tmpB = array_shift($stackB);
        if($tmpB>=$tmpA){
            array_unshift($stackB,$tmpB);
            break;
        }else{
            array_unshift($stackA,$tmpB);
        }
    }
    array_unshift($stackB,$tmpA);
}
print_r($stackB);
Copy after login

Yeah, LZ has been thinking about it for five years and finally realized it today hahahaha~

The above has introduced a lot of profound knowledge~ Sorting can be achieved using only two stacks, including all aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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