Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

无语,自己写的快排就是没有自带的快,一换qsort就过……

Posted by allanlyy at 2008-03-04 16:05:40 on Problem 1002
int cmp(const void* p1, const void* p2)
{
	return *(int *)p1 - *(int *)p2;
}

qsort(output, n, sizeof(int), cmp);

快过:

int Partition(int low,int high)
{
    int cmp;
    cmp = output[low];
    while (low < high)
    {
        while (low < high && output[high] >= cmp) --high;
        output[low] = output[high];
        while (low < high && output[low] <= cmp) ++low;
        output[high] = output[low];     
    }
    output[low] = cmp;
    return low;
}
void QSort(int low, int high)
{
    int pivotloc;
    if (low < high)
    {
        pivotloc = Partition(low, high);
        QSort(low, pivotloc - 1);
        QSort(pivotloc + 1, high);             
    }     
}

QSort(0, n - 1);

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator