//单向快排
int Partition(int *ar , int left , int right)
{
int i = left - 1 , j = left;
int tmp = ar[j];
while(j <= right)
{
if(ar[j] <= tmp)
{
std::swap(ar[i+1] , ar[j]);
i+=1;
}
j+=1;
}
std::swap(ar[left] , ar[i]);
return i;
}
void QuickPass(int *ar , int left , int right)
{
if(left < right)
{
int pos = Partition(ar , left , right);
QuickPass(ar , left , pos - 1);
QuickPass(ar , pos + 1 , right);
}
}
void QuickPass(int *ar , int n)
{
if(ar == NULL && n <= 1) return;
}
//单链表快排(带头结点)
ListNode * ListPartition(ListNode *left , ListNode *right)
{
ListNode *i = left;
ListNode *j = left->next;
ElemType tmp = j->data;
while(j != right)
{
if(j->data <= tmp)
{
swap(i->next->data , j->data);
i = i->next;
}
j = j->next;
}
swap(left->next->data , i->data);
return 1;
}
void ListQuickPass(ListNode *left , ListNode *right)
{
if(left->next != right)
{
ListNode * pos = ListPartition(left , right);
QuickPass(left , pos);
QuickPass(pos , right);
}
}