Lintcode——整数排序 II

1.题目

     给一组整数,按照升序排序。使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法。

样例

     给出 [3, 2, 1, 4, 5], 排序后的结果为 [1, 2, 3, 4, 5]

2.思路

      sort()函数是nlogn的算法,用此函数可以解决此问题。

3.代码

AC代码:

class Solution {
public:
    /**
     * @param A an integer array
     * @return void
     */
    void sortIntegers2(vector& A) {
        // Write your code here
        sort(A.begin(),A.end());
    }
};
错误:

class Solution {
public:
    /**
     * @param A an integer array
     * @return void
     */
    void sortIntegers2(vector& A)
    {
        void quicksort(A,0,A.size()-1);
    }
    public int Partition(vector& A,int first,int end)
    {   
        int i=first,j=end;
        int pivot=A[first];
        while(i& A,int first,int end) {
        // Write your code here
        //sort(A.begin(),A.end());
        if(first

4.感想

         想应用一下学过的快速排序,写了半天却一直过不了。。。。先去写别的题了,回来待思考!!


你可能感兴趣的:(排序)