A quick sort is a quick sort, and the shell sort is a sort of cher. However, when you directly apply a function template based on these algorithms, it can sometimes be inefficient if the comparable object to be sorted is large. The problem is. The problem is that there is too much work to replicate comparable objects when rearranging comparable objects. If the comparable object is large and difficult to replicate, the cost will be high.
In general, the solution to this problem is simple: generate an array of pointers to comparable, and rearrange the pointers. Once you have determined where the element should be, you can place the element directly in the appropriate location without having to do too much intermediate copying. This requires the use of an algorithm that becomes an intermediate permutation.
A lei template that stores object types stored by a class that points to a pointer to comprable pointerTemplate<TypeNameComparable>classpointer{ Public: Pointer (comparable *rhs=null): Pointee (RHS) {}BOOL operator< (Constporinter& RHS)Const{return*pointee < *rhs.pointee;}operatorComparable * ()Const{returnPointee;}Private: Comparable *pointee;}; Algorithms for sorting large objects Tempalte <TypeNameComparable>voidLargeobjectsort ( vector<Comprable>& A) { vector<Pointer<Comparale>> P (a.size ());intI,J,NEXTJ; for(i=0; I<a.szie (); i++) p[i]=&a[i]; Quicksort (P);//shuffle Items in place for(i=0; I<a.size (); i++)if(P[i]! = &a[i]) {comparable tmp=a[i]; for(J=i;p[j]!=&a[i];j=nextj) {nextj=p[j]=&a[0]; A[J]=*P[J]; p[j]=&a[j]; } a[j]=tmp; p[j]=&a[j]; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
An algorithm for sorting large objects