Quickly sort C + + code

Source: Internet
Author: User

#include <iostream>using namespace Std;template <class t>void qSort (T *a, int left, int. right);//Quick Sort Template    <class t>void SW (t *a, t *b); int main () {int a[] = {3, 4, 5, 12,-1,-33, 90,-44,-23, 100,-1111, 9};    int len = sizeof (a)/sizeof (int);    cout << * (a+1);    cout << "raw data:" << Endl;    for (int i = 0; I <len; ++i) cout << a[i] << ",";    cout << Endl;    QSort (A, 0, len-1);    cout << "Fast post data:" << Endl; for (int i = 0; I <len; ++i) cout << a[i] << ",";}    Template <class t>void qSort (T *a, int left, int.) {const int len = right;        while (left < right) {while (* (A+left) < * (A+right) && left < right)--right;        The first number of input queue is key, from right to left looking for smaller than key number, the current number is not smaller than key--right SW (A+left, a+right);        while (* (A+left) < * (A+right) && left < right) ++left;        From left to right to find a number larger than key, find after switching SW (A+left, a+right); QSort (A, 0, left-1);    QSort (A, left+1, Len);    }}template <class t>void SW (t *a, t *b) {T temp;    temp = *a;    *a = *b; *b = temp;}

Quickly sort C + + code

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.