The so-called sorting is to organize records in the file, which is arranged in the order of keywords (or decreasing). It is defined as follows: Enter: N records R1, R2, ..., RN, which correspond to K1, K2, ..., KN, respectively. Output: RIL, RI2, ..., RIN such as Ki1 ≤ Ki2 ≤ ... ≤ Kin. (Or Ki1 ≥ Ki2 ≥ ... ≥ kin).
Here, we briefly introduce several sorting methods, direct insertion, Hidden sort, bubble sorting, rapid sorting, direct selection, code mentioned in the text, is passed under IE6.
Direct Insert Sort Basic Thought Assume that the records to be sorted is stored in the array r [1..n]. Initially, R [1] has one ordered zone, and the disorder zone is R [2..n]. From i = 2 until I = N, R [I] is inserted into the current ordered zone R [1..i-1] to generate an ordered zone containing N records.
Algorithm Description Function INSERTSORT (ARR) {// Insert Sort -> Direct Insert Method Sorting Var ST = New Date (); Var Temp, J; For (VAR i = 1; I -1 && (TEMP) <(arr [j])); Arr [J 1] = Temp;} // endif} status = (new date () - st) 'ms'; return arr;}
Hill Sort Basic Thought First Take a smaller D1 smaller D1 as the first increment, divide all of the files into D1 groups. The records of all the multiple times the DL are placed in the same group. First, direct interrogation in each group; then, take the second increment D2
Algorithm Description
Function shellsort (arr) {// inserts sorting -> Hier sorted var st = new date (); var increment = arr.length; do {increment = (Increment / 3 | 0) 1; arr = shellpass (Arr, Increment;} while (increment> 1) status = (new date () - st) 'ms'; return arr;} function shellpass (arr, d) {// 希儿 排 分 segment execution function var Temp, J For (var i = d; i -1 && (temp) <(arr [j])); arr [j d] = temp;} // endif} Return Arr; } Function shellsort (arr) {// Insert Sort-> Hier sorted VAR ST = New Date (); var increment = arr.length; do {increment = (Increment / 3 | 0) 1; arr = shellpass (Arr , Increment);} while (increment> 1) status = (new date () - st) 'ms'; return arr;} Function shellpass (arr, d) {// 希儿 排 分 segment execution function var Temp, J; for (var i = D; I -1 && (temp) <(arr [ J])); Arr [J D] = TEMP;} // endif} Return Arr;}
Bubble Sort Basic Thoughts will be sorted record array R [1..n] vertical, each record R [i] is considered to be a bubble of R [i] .Key. According to the principle of light bubbles, it cannot be scanned from the bottom, from the bottom to the array R: Anyone who scans the violation of this principles will make it "floating". So repeated, until the last two bubbles are in the light, the heavy people are below.
Algorithm Description Function Bubblesort (Arr) {// Exchange Sort -> Bubble Sort Var ST = New Date (); Var Temp; Var Exchange; for (VAR I = 0; I = i; j -) {IF ((Arr [j 1]) <(arr [j])) {temp = arr [j 1]; Arr [J 1] = Arr [J]; Arr [J] = Temp; Exchange = true;}}}}}}}}}} = (new date () - st) 'ms'; Return ARR Quick Sort Basic Thoughts Decompose the original problem into a sub-problem similar to the structure and the original problem. Recursively explain these subproises, and then combine the solution of these sub-problems as the solution. On R [Low..high], one record is selected as the reference (Pivot), and the current unordered area is divided into left and right two smaller sub-intervals R [Low..PivoS-1) and R [Pivotpos 1..high], and make all records of all records in the left sub-interval are less than or equal to the keyword of the reference record (may not mark the pivot) pivot.key, all records in the sub-area in the right are larger than Wait for Pivot.Key, and the reference record Pivot is on the correct location (Pivotpos), it does not need to participate in subsequent sorting.
Algorithm Description Function Quicksort (Arr) {// Exchange Sort-> Quick Sort IF (Arguments.Length> 1) {var Low = arguments [1]; var high = arguments [2];} else {var low = 0; var High = arr.length-1;} if (low = Pivot) J -; IF (i
Direct sequencing directly selects the direct sequencing of the N-1 思 N records can be sorted by N-1 Direct selection: 1 Initial state: the unordered area is R [1..n], ordered zone is empty. 2 The first sort is selected in the unordered area R [1..n], the minimum record R [K] is selected, and it exchanges it with the first record R [1] of the unordered area, so that R [1 ..1] and R [2..N] varies to the number of new ordered zones that reduce the number of new ordered regions and records. ... 3 I i 排 第 第 排 排 排 排 为 有 有 区 区 区 区 区 区 区 区 区 区 区 区 区 区 区 区 区 区 区. This sort is selected from the current disorder zone minimized recording R [K], exchange it with the first record R [i] of the unordered area, so that R [1..i] and R [i 1..n] The number of new ordered districts that have been changed to recording a number of new ordered zones and records reduced by 1. In this way, the direct selection of N records can be sequentially selected by N-1 to obtain ordered results. Algorithm Description Function SelectSort (Arr) {// Select Sort -> Direct Selection Var ST = New Date (); Var Temp; for (VAR i = 0; I
The code is as follows:
FIELDSET {
FONT-SIZE: 12PX;
Padding: 10px;
Width: 80%;
MARGIN: AUTO;
}
INPUT {
FONT-SIZE: 12PX;
Font-family: tahoma;
}
style>
Sort by Title>
Sort by h3>
Direct insertion sorting b>
Please enter a character to be sorted, separated by a half-way comma