本文整理汇总了C++中QuickSort函数的典型用法代码示例。如果您正苦于以下问题:C++ QuickSort函数的具体用法?C++ QuickSort怎么用?C++ QuickSort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QuickSort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: QuickSort
void QuickSort(rde::vector<void *> & SortList, intptr_t L, intptr_t R,
CompareFunc SCompare)
{
intptr_t Index;
do
{
Index = L;
intptr_t J = R;
void * P = SortList[(L + R) >> 1];
do
{
while (SCompare(SortList[Index], P) < 0)
Index++;
while (SCompare(SortList[J], P) > 0)
J--;
if (Index <= J)
{
if (Index != J)
{
void * T = SortList[Index];
SortList[Index] = SortList[J];
SortList[J] = T;
}
Index--;
J--;
}
}
while (Index > J);
if (L < J)
QuickSort(SortList, L, J, SCompare);
L = Index;
}
while (Index >= R);
}
开发者ID:gumb0,项目名称:Far-NetBox,代码行数:34,代码来源:Classes.cpp
示例2: QuickSort
void TList::Sort(CompareFunc Func)
{
if (GetCount() > 1)
{
QuickSort(FList, 0, GetCount() - 1, Func);
}
}
开发者ID:nineclock,项目名称:Far-NetBox,代码行数:7,代码来源:Classes.cpp
示例3: QuickSort
void Pedigree::MakeSibships()
{
Person ** sibs = new Person * [count];
for (int i = 0; i < count; i++)
sibs[i] = persons[i];
QuickSort(sibs, count, sizeof (Person *),
COMPAREFUNC Pedigree::CompareParents);
for (int first = 0; first < count; first++)
if (!sibs[first]->isFounder())
{
int last = first + 1;
while (last < count)
if (sibs[first]-> mother != sibs[last]->mother ||
sibs[first]-> father != sibs[last]->father)
break;
else last++;
last --;
for (int j = first; j <= last; j++)
{
if (sibs[j]->sibCount) delete [] sibs[j]->sibs;
sibs[j]->sibCount = last - first + 1;
sibs[j]->sibs = new Person * [sibs[j]->sibCount];
for (int k = first; k <= last; k++)
sibs[j]->sibs[k - first] = sibs[k];
}
first = last;
}
delete [] sibs;
}
开发者ID:mkanai,项目名称:ChunkChromosome,代码行数:32,代码来源:Pedigree.cpp
示例4: QuickSort
void QuickSort(int* arr, size_t size) {
// Complexity T(n) = O(n*log(n))
if (size <= 1)
return;
// amazing not naive partition implementation
int key = rand() % size, i = 1; // i points on pivot element
swap(arr[0], arr[key]);
for (size_t j = 1; j < size; j++) { // j points on unsorted element
if (arr[j] < arr[0])
swap(arr[i++], arr[j]);
}
swap(arr[0], arr[i-1]);
QuickSort(arr, i-1);
QuickSort(arr + i, size - i);
}
开发者ID:Dragollla,项目名称:ITMO,代码行数:17,代码来源:Algorithms.cpp
示例5: QuickSort
/* This function does the quicksort
Arguments :
array - the array to be sorted
startIndex - index of the first element of the section
endIndex - index of the last element of the section
*/
void QuickSort(int* array, int startIndex, int endIndex)
{
int pivot = array[startIndex]; //pivot element is the leftmost element
int splitPoint;
if(endIndex > startIndex) //if they are equal, it means there is
//only one element and quicksort's job
//here is finished
{
splitPoint = SplitArray(array, pivot, startIndex, endIndex);
//SplitArray() returns the position where
//pivot belongs to
array[splitPoint] = pivot;
QuickSort(array, startIndex, splitPoint-1); //Quick sort first half
QuickSort(array, splitPoint+1, endIndex); //Quick sort second half
}
}
开发者ID:janwieners,项目名称:TED,代码行数:23,代码来源:quicksort.cpp
示例6: QuickSort
void QuickSort(int arr[], int left, int right) {
int pivot = Median3forQuickSort(arr, left, right);
int* l = &arr[0];
int* r = &arr[N-1];
while(1) {
while (arr[++l] < pivot) {;}
while (arr[--r] > pivot) {;}
if (l < r) {
swap(&arr[l], &arr[r]);
} else {
break;
}
}
swap(&arr[l], &arr[right-1])
QuickSort(arr, left, l-1);
QuickSort(arr, l+1, right);
}
开发者ID:HsinyaoTsai,项目名称:MOOCDataStructure,代码行数:17,代码来源:Sort.c
示例7: QuickSort
void QuickSort(int a[], int left, int right)
{
if(left < right)
{
int i = left, j = right, p = a[i];
while(i < j)
{
while(i < j && p < a[j]) j--;
if(i < j) a[i++] = a[j];
while(i < j && p > a[i]) i++;
if(i < j) a[j--] = a[i];
}
a[i] = p;
QuickSort(a, left, i-1);
QuickSort(a, i+1, right);
}
}
开发者ID:FeifeiWang7,项目名称:LeetCode,代码行数:17,代码来源:ThreeSum.c
示例8: QuickSort
void QuickSort(void** Table, int Size, CompCallback Callback) {
void* Pivot = NULL;
int PivotIdx = 0;
//A table consisting of one element is always sorted.
if(Size <= 1)
return;
/**
* Find the pivot, then put all elements that are less than the pivot on the left of its
* and all elements that are greater on the right of the pivot, then subdivde the table
* in to two and repeat.
*/
Pivot = MedianPivot(Table, Size);
PivotIdx = QuickSortPartition(Table, Size, Pivot, Callback);
QuickSort(Table, Size - (Size - PivotIdx), Callback);
QuickSort(Table + PivotIdx, (Size - PivotIdx), Callback);
}
开发者ID:Raugharr,项目名称:Herald,代码行数:17,代码来源:Array.c
示例9: QuickSort
/*Quicksort - to sort jobs */
int QuickSort(Jobs A[],int low, int high,int k)
{
int pivot;
int n;
n = high-low+1;
if(n > 1)
{
pivot = partition(A,low,high,k);
if(low < pivot-1)
QuickSort(A,low,pivot-1,k);
if(pivot+1 < high)
QuickSort(A,pivot+1,high,k);
}
return 0;
}
开发者ID:manasayp,项目名称:Algorithms_Coursera,代码行数:18,代码来源:Job_Scheduling.cpp
示例10: main
void main()
{
int dat[] = { 9,2,65,3,5,2,8,6,10,4 };
QuickSort(dat, 0, 9);
for (int i = 0; i < 10; i++)
std::cout << dat[i] << std::endl;
getchar();
}
开发者ID:liyumeng,项目名称:AlgorithmCourse,代码行数:8,代码来源:QuickSortSource.cpp
示例11: Q_Sort
int Q_Sort(queue *q, int (*Comp)(const void *, const void *))
{
int i;
void *d;
datanode *dn;
/* if already sorted free memory for tag array */
if(q->sorted) {
efree(queue_index);
efree(queue_posn_index);
q->sorted = False_;
}
/* Now allocate memory of array, array of pointers */
queue_index = emalloc(q->size * sizeof(q->cursor->data));
if(queue_index == NULL)
return False_;
queue_posn_index = emalloc(q->size * sizeof(q->cursor));
if(queue_posn_index == NULL) {
efree(queue_index);
return False_;
}
/* Walk queue putting pointers into array */
d = Q_Head(q);
for(i=0; i < q->size; i++) {
queue_index[i] = d;
queue_posn_index[i] = q->cursor;
d = Q_Next(q);
}
/* Now sort the index */
QuickSort(queue_index, 0, q->size - 1, Comp);
/* Rearrange the actual queue into correct order */
dn = q->head;
i = 0;
while(dn != NULL) {
dn->data = queue_index[i++];
dn = dn->next;
}
/* Re-position to original element */
if(d != NULL)
Q_Find(q, d, Comp);
else Q_Head(q);
q->sorted = True_;
return True_;
}
开发者ID:AllenJB,项目名称:php-src,代码行数:58,代码来源:queue.c
示例12: QuickSort
void QuickSort(int *pnArr, int nLeft, int nRight)
{
if (nLeft < nRight)
{
if (nRight - nLeft > K)
{
int nTmpPos = RandomPartition(pnArr, nLeft, nRight);
QuickSort(pnArr, nLeft, nTmpPos - 1);
QuickSort(pnArr, nTmpPos + 1, nRight);
}
else
{
InsertSort(pnArr, nLeft, nRight);
}
}
}
开发者ID:Juntaran,项目名称:Data-Structure-Algorithm,代码行数:18,代码来源:011.7.4-6快速排序改良版+随机选三个数来确定主元素.cpp
示例13: Changing
void TStringList::CustomSort(TStringListSortCompare ACompareFunc)
{
if (!GetSorted() && (GetCount() > 1))
{
Changing();
QuickSort(0, GetCount() - 1, ACompareFunc);
Changed();
}
}
开发者ID:nineclock,项目名称:Far-NetBox,代码行数:9,代码来源:Classes.cpp
示例14: main
int main(){
int v[TAM] = {7, 13, 5, 8, 9, 2, 3};
QuickSort(v, 0, TAM-1);
ImprimeVetor(v, TAM);
return(0);
}
开发者ID:WaGjUb,项目名称:Estrutura_de_dados_2,代码行数:9,代码来源:ex4.c
示例15: while
// 퀵 소트
void CRankDlg::QuickSort(int first, int last)
{
int pivot, left, right ;
if (first < last) {
pivot =(last +first) /2 ;
left =first ; right =last ;
while (left < right) {
while (_ttoi (rankList.GetItemText (left, 0)) <= _ttoi (rankList.GetItemText (pivot, 0)) && left < last) left++ ;
while (_ttoi (rankList.GetItemText (right, 0)) > _ttoi (rankList.GetItemText (pivot, 0))) right-- ;
if (left < right) SwapItem (left, right) ; // 교환
}
SwapItem (pivot, right) ;
QuickSort (first, right -1) ;
QuickSort (right +1, last) ;
}
}
开发者ID:astroluj,项目名称:MFC,代码行数:19,代码来源:RankDlg.cpp
示例16: SortWordForBook
// 3. sort the word list according to the word frequency (P)
errorType SortWordForBook(bookType* book)
{
wordFreq* wf = NULL;
wf = book->wordList;
QuickSort(wf, NULL);
return ERROR_NONE;
}
开发者ID:HongbiaoYang,项目名称:MPI_Word_Sorting,代码行数:10,代码来源:saveWords.c
示例17: main
int main() {
int A[] = {10,23,3,42,55,7,7,8,9,12};
QuickSort(A,0,9);
int i = 0;
for(; i < 10; i ++) {
printf("%d ",A[i]);
}
return 0;
}
开发者ID:tenywen,项目名称:Algorithm,代码行数:9,代码来源:QuickSort.c
示例18: AppendData
// add rubi data and sort the data
BOOL scRubiArray::AddRubiData( scRubiData& rd )
{
if ( IsRubiData( rd.fStartOffset, rd.fEndOffset ) )
return false;
AppendData( (ElementPtr)&rd );
QuickSort( rubi_sort );
return true;
}
开发者ID:jimmccurdy,项目名称:ArchiveGit,代码行数:10,代码来源:scrubi.cpp
示例19: main
int main()
{
int array[] = {7,6,5,3,4,2,1,10,9,8};
int len = sizeof(array) / sizeof(int);
PrintArray(array,len,"快速排序前:");
QuickSort(array,0,len - 1);
PrintArray(array,len,"快速排序后:");
return 0;
}
开发者ID:LucasYang7,项目名称:Sort-Algorithm,代码行数:9,代码来源:main.cpp
示例20: main
main() {
int n = 0, a;
while(scanf("%d", &Data[n]) == 1)
n++;
QuickSort(0, n-1);
for(a = 0; a < n; a++)
printf("%d ", Data[a]);
return 0;
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:9,代码来源:QuickSort.cpp
注:本文中的QuickSort函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论