


Such profound knowledge~ Sorting can be achieved using only two stacks
Jul 29, 2016 am 09:05 AM$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);
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.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Sort array using Array.Sort function in C#

Simple and clear method to use PHP array_merge_recursive() function

How to use the array_combine function in PHP to combine two arrays into an associative array

Detailed explanation of PHP array_fill() function usage

How to use the Array module in Python

What are the common causes of ArrayStoreException in Java?

Introduction to how to use the PHP array_change_key_case() function

What are the common causes of ArrayIndexOutOfBoundsException in Java?
