First, quick sort1. Upgraded bubble sort + recursion2. Compare when selecting a comparison pivot object so that its left is less than it, and the right side is greater than it.3. Re-order data recursively on both sides of the pivot objectSecond, the code examplepublic class QuickSort{public static int partition (int[] n, int. left, int. right){int pivotkey = N[left];Piv
position7QuickSort (r,low,pivotpos-1);//fast row of left interval8QuickSort (r,pivotpos+1, high);//Quick row of right bands9 }Ten}(2) Partitioning algorithm partitionSimple partitioning algorithm step: ① Initialization--set two pointers I and J, the initial value is the lower bound and upper bounds of the interval, set the interval lower bound r[i]=r[1]=pivot for the Datum record ② J from N to the left scan, find the first keyword less than r[k].key
, 40, 80, 60, 20} is now sorted. We can learn the subtlety of fast sorting through code explanation.Let's look at the code./* Perform quick sorting on the sequence table L */
Void QuickSort (SqList * L)
{
QSort (L, 1, L-> length );
}
It is also a code, just like merging and sorting. Because recursive calling is required, we encapsulate a function. Now let's look at the implementation of QSort./* Perform fast sorting on the subsequence L-> r [low... high] in sequence table L */
Void QSort (SqList
Today, the next ranking algorithm, including the bubble sorting method and direct sorting method, these are relatively simple, but the rapid sorting method is difficult, so the focus of research.First say the principle: the rapid sorting method is the recursive way to treat the order of the sequence of several operations, each operation so that the number of parts of the operation of an element is divided into two parts, part is less than the cutoff value, the other part is greater than the cuto
Package utils.sort;
/**
* Quick sort, requiring that the array to be sorted must implement the comparable interface
*/
public class QuickSort implements Sortstrategy
{
private static final int CUTOFF = 3; Use fast sorting when the number of elements is greater than this value
/**
* Using the Quick sort algorithm to sort the array obj, requires that the arrays to be sorted must implement the comparable interface
*/
public void sort (comparable[] obj)
{
if (obj = null)
{
throw new NullPointerExc
Http://www.cnblogs.com/gaizai/p/3753296.htmlI. What is covered in this article (Contents)
What is covered in this article (Contents)
Background (contexts)
Implementation code (SQL Codes)
Method One: Use splicing SQL, static column field;
Method two: Using splicing sql, dynamic column field;
Method Three: Use pivot relational operator, static column field;
Method four: Using
first, the algorithm thoughtThe quick sort is a sort of division exchange proposed by C.r.a.hoare in 1962. It adopts a strategy of division, which is usually referred to as the Division method (Divide-and-conquermethod).(1) The basic idea of division and Administration LawThe basic idea of divide-and-conquer method is: to decompose the original problem into several sub-problems with smaller size but similar structure to the original problem. Solve these sub-problems recursively, then combine the
1. Algorithm IdeaQuick Sort is a sort of divided interchange. It adopts a strategy of division, which is usually referred to as the Division method (Divide-and-conquermethod).(1) The basic idea of division and Administration LawThe basic idea of divide-and-conquer method is: to decompose the original problem into several sub-problems with smaller size but similar structure to the original problem. Solve these sub-problems recursively, then combine the solutions of these sub-problems into the sol
The first is the description and analysis of next permutation's algorithm as follows:the first is to know the idea, programming to pay attention to the use of STL voidNextpermutaion (vectorint> num) {next_permutation (Num.begin (), Num.end ()); }Private: TemplateBOOLnext_permutation (bidiit First, bidiit last) {//Reverse, Attention! Auto Rfirst = reverse_iterator(last); Auto Rlast= reverse_iterator(first); Auto Pivot=Next (Rfirst); while(
(int heap [], int a, int n ){Int temp;Temp = heap [a];Heap [a] = heap [n];Heap [n] = temp;}} Insert sorting algorithm directly The code is as follows:Copy code Public class InsertionSort {Public static void main (String [] args ){Int arr [] = new int [] {20, 40, 90, 30, 80, 70, 50 };System. out. println ("original array :");For (int x: arr) {// Print the array before sorting;System. out. print (x + "\ t ");}Int I;Int j;Int tmp;For (I = 1; I Tmp = arr [I];// This section
to have a deep experience and understanding of what they are responsible for and what organizations they are in. Understand the details and often defend against crisis beforehand.
Company Concept
Successful managers should all be bole. Bole's responsibility lies in the selection and selection of "smarter talents than him", but it is absolutely impossible to select famous but arrogant enterprise "stars ". In a highly competitive society, highly-efficient enterprises cannot afford the employees w
space
While (j {// Merge Records in SR from small to large into trTr [p ++] = (Sr [J] }While (j {// Copy the remaining SR [I. m] to trTr [p ++] = Sr [J ++];}While (k {// Copy the remaining SR [J. N] to trTr [p ++] = Sr [k ++];}// Return the ordered result to the SRFor (j = I, P = 0; j {Sr [J] = tr [p];}
Return;}/*************************************** ****************************
File Name: qsort. cppAbstract: C ++ implementation of quick sortingDevelopment Platform: Win XP SP2Compiling environ
Data Structure-Summary of various sorting algorithms [continued], data structure AlgorithmsSummary of various sorting algorithms 3. Exchange sorting [connected]
2. Quick sorting
Quick sorting refers to dividing the columns to be sorted into two parts by comparing key codes and switching records and taking a record as the boundary (this record is called the pivot point. Among them, the key code of some records is greater than or equal to the key code o
and drag to rotate in either direction. This is the selected state: Like other tools, theRect tool uses the current pivot mode and space to set pivot and Local in the toolbar . It's usually a good idea to work with the UI. Toolbar buttons set to Pivot and Local2.2 Rect TransformRect transform is a new transform component that is used for all UI elements, not re
= 0;for (int i = 0; i "Efficiency analysis"Space efficiency: Only one sub-cell is used.time Efficiency: Assuming that the number of elements to be sorted is n, then a total of n-1 will be ordered, the sub-sequence of J elements for a trip to bubble sort needs to be j-1 sub-keyword comparison. Thus, the total number of comparisons for the bubble sort is /span> Therefore, the time complexity of bubble sorting is 0 (N~2) 2. Quick Sort The beauty of it i
Basic idea:By a trip to the sorting of records into separate two parts, some of the records of the keywords are smaller than the other part of the keyword, you can separate the two parts of the record to order to achieve the overall orderly purpose.Popular point is that:Find a record in the pending record, and then find a way to put it in a position, it is the left side of the value is smaller than him, the right side of the value is greater than he (positive order or reverse), the record is cal
Six, quick sortThe quick sort is divided into two parts by a set of elements that follow the first element (this is a dynamic process change), the previous part is smaller than he (or so), and the latter part is larger than it. The process is then recursively passed through the appropriate program, and when there is no exchange the instructions need to exit recursively.。 Quick sort uses the Divide and conquer strategy to divide a sequence (list) into two sub-sequences (sub-lists).The steps are:
is larger than the datum, and put it on the right sub-list. After scanning the sorted list, the node value of the left face list is less than the value of the datum, the value of the right sub-list is greater than the datum, and then the datum is inserted into the list and used as a bridge to connect two sub lists. Then, according to the number of nodes in the left and right sub lists, the smaller ones are sorted by recursion, and the number is iterated.
The variables used in the sort function
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.