The following introduces you to four commonly used sorting algorithms:
1. Bubble sorting
Features: low efficiency, simple implementation?
Idea (sort from small to large): In each pass, move the largest element in the sequence to be sorted to the end, and the remainder is the new sequence to be sorted. Repeat the above steps until all elements are sorted. This is just a type of bubble sorting, of course it can also be sorted from back to front.
2. Selection sorting
Features: low efficiency and easy to implement. ?
Idea: In each pass, select the smallest element from the sequence to be sorted and place it at the end of the sorted sequence. Repeat the above steps for the remaining elements in the sequence to be sorted until the sorting is completed.
3. Insertion sort
Features: low efficiency and easy to implement. ?
Idea: Divide the array into two parts, compare the elements in the latter part with the elements in the previous part one by one, and replace the current element array[i] if it is small. Find a reasonable position to insert array[i]
4. Quick sort
Features: efficient, time complexity is nlogn. ?
Adopt the idea of ??divide and conquer method: first set an axis value pivot, and then use this axis value as the dividing basis to divide the sequence to be sorted into two parts larger than the pivot and smaller than the pivot, and then divide the sequence into two parts. Perform quick sort on the subsequence until the subsequence contains one element.
Why is it that online booking, which shows that tickets are available for purchase, is not available?