bool TopX_partion::FindTopX(unsigned int X) { LogsInforVector::size_type size = m_pDataSourceVec->size(); if (NULL == m_pDataSourceVec || X < 1 || X > size) return false; // 在size个中找出top size,不需要处理 if (X == size) return true; LIVectorIterator it = m_pDataSourceVec->begin(); LIVectorIterator first = m_pDataSourceVec->begin(); LIVectorIterator last = m_pDataSourceVec->end() - 1; m_targetIter = first + size - X; // 利用快排查找最大的K个数 while(first < last) { it = Partion(first, last); if (it == m_targetIter) return true; else if (it > m_targetIter) last = it - 1; else if (it < m_targetIter) first = it + 1; } return false; }
void QuickSort(int *s, int beg, int end) { if (beg < end - 1) { int mid = Partion(s, beg, end - 1); QuickSort(s, beg, mid); QuickSort(s, mid + 1, end); } }
void QuickSort(int s,int t,double* A,int* index) { int q; if(s>=t) return; q = Partion(s,t,A,index); QuickSort(s,q-1,A,index); QuickSort(q+1,t,A,index); }
void Quick_Sort(datatype *arr, int s, int t) { if (s < t) { int m = Partion(arr, s, t); Quick_Sort(arr, s, m - 1); Quick_Sort(arr, m + 1, t); } }
void QuickSort(int arr[], int low, int high) { int pivotLocation; if(low < high){ //将待排序数组一分为二 pivotLocation = Partion(arr, low, high); //递归排序两个数组,其中枢轴位置可以不用参与排序 QuickSort(arr, low, pivotLocation-1); QuickSort(arr, pivotLocation+1, high); } }
/** * @brief QuickSort\n * 快速排序 * @param[in] *List 双向链表默认链表接口 * @param[in] *one 比较的第一个内容 * @param[in] *two 比较的第二个内容 * @param[in] *CallBackCmp 各种类型的回调函数接口 */ void QuickSort(DLNode * List, DLNode * p_one, DLNode * p_two, int (*CallBackCmp)(const void *, const void *)) { DLNode * p_temp = NULL; p_temp = Partion(List, p_one, p_two,CallBackCmp); if ( p_one != p_temp ) { QuickSort(List, p_one, p_temp->back,CallBackCmp); } if ( p_two != p_temp ) { QuickSort(List, p_temp->next, p_two,CallBackCmp); } }