Fast sorting algorithm

Source: Internet
Author: User

The fast sorting algorithm is a very efficient internal sorting algorithm with an average time complexity of O (Nlogn), and its performance is best in the same time complexity, but

In the worst case, it will degenerate into a bubbling sort, where the time complexity is O (n^2). In terms of average performance, fast sequencing is a very efficient algorithm, and now

This paper introduces a simple implementation algorithm for fast sorting.

The code is as follows:

#include <stdio.h> #define  N  10int main () {void sort (int *a, int left, int. right), int a[n];int i;for (i = 0; i < N; i++) scanf ("%d", &a[i]); sort (A, 0, N-1);     Defect, when called in the main function, to check if left is less than rightfor (i = 0; i < N; i++) printf ("%d", A[i]); return 0;} void sort (int *a, int left, int right) {if (left < right)   //When only one data is returned, that is, leave = = Right{int Key = A[left];int Low = Le Ft;int high = right;while (Low < High) {when (Low < high && A[high] >= key) High--;a[low] = A[high];while (l ow < high && A[low] <= key) Low++;a[high] = A[low];} A[low] = Key;sort (A, left, low-1);   Sort the left half (a, low+1, right);  Sort the right half of the part}}

  

Fast sorting algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.