<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" >
var arr = [1, 2, 4, 5, 7, 10]
Quick Sort
You have a bunch of coins, the year on the coin is different, you're going to era name the coin right now.
The first step: you take out the year is probably the year area of the one-second of a coin (is the computer out of the array first)
Step two: Compare each of the remaining coins with the year of the coin, which is larger than the right side of the coin year, and less than the left side.
So you get two piles of coins, a bunch that's smaller than the year you picked the coins, and a bunch that's bigger than the year you picked the coins.
The third step: the two piles of coins, respectively, as the beginning of the pile of coins, and then select the year is probably the year area of One-second of a coin
Fourth step: (Suppose I choose a pile of coins on the left), then repeat the second step, and get two piles of coins
Fifth Step: (then select a pile of coins on the left), repeat the first step, step two, step three.
The number of coins is limited, a coin has only one year, it is impossible to have a coin in two halves, so when that pile of coins is a coin, you have finished the pile.
It's tiring and annoying for people to do this, but for a computer it can run the same code as long as it repeats, and it will soon be resolved
function QuickSort (arr) {
if (arr.length <= 1) {return arr;}
If there is only one or none of the coins, then it is not a direct result.
var pivotindex = Math.floor (ARR.LENGTH/2);
Select a coin that is roughly one-second of the area of the selected year
var pivot = Arr.splice (pivotindex, 1) [0];
The coins you have chosen can no longer be counted in the pile of coins to be stored separately.
var left = [];
First define the coin stack on the left.
var right = [];
First define the coin stack on the right.
for (var i = 0; i < arr.length; i++) {
To compare all the coins
if (Arr[i] < pivot) {
Smaller than the year of your choice of coins, put a bunch on the left
Left.push (Arr[i]);
} else
{
Bigger than the year of your choice, put a pile on the right.
Right.push (Arr[i]);
}
}
Return QuickSort (left). Concat ([pivot], QuickSort (right));
Put your chosen coin in the middle of a pile of coins
}
Console.log (QuickSort (arr));
</script>
<body>
</body>
Quick ordering of arrays