1. Simple Steps (numbers increase progressively from left to right)
1. Identify the principal element, which can be any element. Here we always select the last most principal element.
2. Search from left to right, and place smaller than the principal component to the left.
3. After the end is found, the principal component is exchanged with the next number on the left that is less than the principal component.
In this way, the left side of a principal component is smaller than the principal comp
Oracle database, we only need to change the value in the configuration file to "oracledbfactory. This structure is highly scalable and can effectively solve the problems arising from future demand changes. To imagine such a requirement, we need to provide a sort component for our framework. Currently, we need to implement Bubble sorting algorithms and quick sorting algorithms. Based on the idea of "interface-oriented programming", we can provide a unified interface isort for these sorting algor
Int [] Max = {6, 5, 4, 0} is a known array. Sort it in descending order using a fast Sorting Algorithm and return an array.
Public class testquicksort {
Private int [] array = NULL;
Private void quicksort (INT lowest, int highest ){If (array = NULL | lowest | Highest> = array. Length ){Return;}Int low = lowest;Int high = highest;Int key = low ++;For (; low If (Key If (array [Key]> array [High]) {Array [High] = array [Key] + (array [Key] = array [High
(n) =θ (NLGN)
It can be seen that, when the good, the difference divides alternately appear, the fast row's running time is like all good division, still is θ (NLGN).
Three, the optimization of the fast row
As you can see from the above analysis, fast sorting is slow in the input order or reverse, and in the rest of the case it behaves well. If the input itself has been sorted, then it's bad. So how do we make sure that it gets better average performance for all the inputs? Quick sort in fro
Quick Sortpersonal thoughts are chaotic, suggest to read the original text directlySimple version:defPARTITION (A, P, R): x= A[r]#Anchor main element {greater than it put aside, less than put on the other side}i = P-1 forJinchRange (P, r):ifA[J] x:i+ = 1A[i], A[j]=A[j], A[i] a[i+1], a[r] = A[r], a[i+1] returni + 1defQUICKSORT (A, P, r):ifP #Divide and conquerQ =PARTITION (A, p, R) QUICKSORT (A, p, Q-1) QUICKSOR
; Packagecom.ynu.www.tool;
Public class QuickSort {
public int Getmiddle (int[] arrayint, int. Low, int.) {
int tmp = Arrayint[low];
While (Low
While (Low
high--;
}
Arrayint[low] = Arrayint[high]; //smaller than mid-axis records moved to the low end
While (Low
low++;
}
Arrayint[high] = Arrayint[low];
}
Arrayint[low] = tmp;
return low;
}
public void Q
Fast sorting algorithm Quicksortvoid QuickSort (Seqlist r,int low,int High){//To R[low. High] Quick Sortint pivotpos;//position of the base record after dividingif (LowPivotpos=partition (R,low,high);//To R[low. High] do divideQuickSort (r,low,pivotpos-1);//left-interval recursive sequencingQuickSort (R,pivotpos+1,high);//Right interval recursive ordering}}//quicksortAttention:To sort the entire file, just call Qu
blog about merge sort, it's easy to understand that recursion is needed here.First on the code:} Public void QuickSort (integer[] A,integer Low,integer high) { if(Low >= high ) return ; = partion (a,low,high); QuickSort (a,low,j); QuickSort (a,j+1, High); } This is the code of the recursive call, we do not care a
to the keywords of the benchmark record (which may be recorded as benchmark)Keyword. key, the key of all records in the subinterval on the right is greater than or equal to the keyword. Key, while the benchmark record is located in the correct position (pivotpos), it does notFollow-up sorting is required. Note: The key to division is to determine the location of the benchmark record, TPOs. The division result can be simply expressed as (note that partition = R [pivotpos]): R [low... pivotpos-1]
inherited from C. thus, in C ++, They shoshould be only used for interfacing C code and existing callback interfaces. setting t for these situations, you shocould use virtual methods or functors, not callback functions.
A simple implementation exampleNow, follow the example that can be found in the attached files. I have created a Dynamic Linked Library called sort. dll. It exports a type called comparefunction:
Typedef int (_ stdcall * comparefunction) (const byte *, const byte *);
Which will
Sorting ", however, a comparison is performed about n times before each merge to separate an element from the merge. Therefore, the time complexity of this sort is still O (N * logn), and the number of comparisons is about twice that of the merge sort.For max_ratio selection, based on my experience, it should be better to select numbers between 4 and 16. I chose 8.In fact, the implementation is more complicated than the above mentioned. First, when the sequence length is not greater than 16, in
){
Right --;
}
Else {
Array [left] = array [right];
Left ++;
Left_flag = true;
}
}
}
Array [left] = tmp;
Quick_sort (array, left); // array [0]-array [left-1]
Quick_sort (array + left + 1, n-left-1); // array [left + 1], array [n-1]
}
In fact, quick sorting is proposed as an improvement of Bubble sorting. Many implementations are implemented through element exchange. The above code is improved and more efficient, converts an element exchange to an element assignment.In general, swap sorting inc
(1) Objective in solving the actual problem, we found that many problems can be attributed to sorting and querying data. The query efficiency depends largely on the sorting efficiency, especially when the data volume reaches the sea level. Therefore, designing an effective sort algorithm is crucial. This article designs a General C ++ quicksort template class. By simply providing a data class, you can implement a fast Sorting Algorithm for any data
person. There is no obvious merits and demerits of the points, as long as they can understand, you can! The next thing I'm going to talk about is the version of the algorithm introduction.QUICKSORT (A, p, R)1 if p 2 then Q←partition (A, p, r)//Key3 QUICKSORT (A, p, q-1)4 QUICKSORT (A, q + 1, R)The key to the fast sorting algorithm is the partition process (array partitioning), which is to a[p. R] for in-pl
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.