Use Quick sort in qt

Source: Internet
Author: User

Today I thought about using QT to do a quick sort, so I studied it a bit.
Because of the habit, C + + Std::sort, even if it is a C time is also used stdlib.h in the qsort.

Handwriting board
The fast-line of the tablet is actually not difficult, but since the use of C + + after the ACM has rarely been knocked naked.

where C language Stdlib
Features: Sorting using the quick sort routines
Usage: void qsort (void base,int nelem,int width,int (*fcmp) (const void , const void *));
Parameters:
1 array first address to sort
2 number of elements to be sorted in the array
3 space size of each element
4 A pointer to a function that determines the order of the sort
This library function is supported in QT, but I do not use it very much now, and this function does not support the sort of STL.

Then the sort of the < algorithm > in the standard library, which is a C + + in a specific sort of generic data, but written in QT does not recognize the sort, std::sort. In fact, we can understand that string is converted to qstring, so we guess it's qsort.
Usage is the same as sort.

Header: < algorithm> namespace:std

bool capitysort  (const  Svideochip  msvideofirst,const svideochip  msvideosecond) {return  (Msvideofirst.mi64videocapacity < msvideosecond.mi64videocapacity); } void * videosort  (qlist  <svideochip  >* msvideochiplist) {qSort (Msvideochiplist-> (), Msvideochiplist->end  (),  Capitysort ); // STD:  :sort  (Msvideochiplist->begin  (), Msvideochiplist-> End  (), capitysort ); } 

Use quick sort in qt

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.