Quick sort of getting started

Source: Internet
Author: User

1 /*2 Quick sort of getting started3 complexity of Time: O (NLOGN)4 The worst case time complexity can reach O (n^2)5 An introduction to self-algorithmic learning6 */7#include <iostream>8 using namespacestd;9 intA[] = {3,7,8,5,4,6,2,1,3};Ten voidQuick_sort (int*,int,int); One voidSwapint,int); A voidprint (); - intMain () - { thePrint ();//before sorting -Quick_sort (A,0,8); -Print ();//after sorting - } + voidprint () - { +      for(intI=0; a[i]!=0; ++i) Acout << A[i] <<" "; atcout <<Endl; - } - voidSwapintXinty) - { -     intt =A[x]; -A[X] =A[y]; inA[y] =T; - } to voidQuick_sort (intA[],intLintR//separate the <t and the >=t + { -     if(L >=R) the         return ; *     intt = A[r],j = L1;//Boundary Problems $      for(intI=l; i<r; ++i)Panax Notoginseng         if(A[i] <t) -         { the++J; +             if(I! =j) A swap (I,J); the         } +Swap (j+1, R); - Quick_sort (a,l,j); $Quick_sort (a,j+2, R); $}

Quick sort of getting started

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.