js four commonly used sorting algorithm

1. bubble sort
analysis:
1, two adjacent elements are compared, the former than the latter if a large, then the switch position
2, when the first round of the last element is the largest
3, because after an operation after , the last element is the largest. So the second time to-one comparison will be less than the last round

js four commonly used sorting algorithm
2. Quick Sort
analysis: 1. Take the intermediate data corresponding to the index and the data were compared with the remaining number of intermediate, a small aside, the other side of a large discharge.
2, then the left or right, respectively, the data repeats the above operation. Recursive calls, both sides can achieve rapid sequencing
js four commonly used sorting algorithm
3. Insertion Sort
resolve
1. The first element is the default
2 to the next element, so that the element is compared with its previous element
3. If the element is large than the previous, the the element moves HERE
4. repeat 3 repeat until the condition is not satisfied
5. the position of the element is inserted into the js four commonly used sorting algorithm
second method
js four commonly used sorting algorithm
4. select the sort
analysis: selecting an initial value of 1, the value of its rear elements one by comparing the position of the exchangejs four commonly used sorting algorithm

Guess you like

Origin blog.51cto.com/14584021/2462172