Several ranking method javascript

Related Tags:

  The so-called sequencing, is to collate documents and records, so that it increased by keyword (or descending) order up.    Its exact definition is as follows: 
  Input: n records R1, R2,…, Rn, and the corresponding keyword, respectively K1, K2,…, Kn. 
  Output: Ril, Ri2,…, Rin, making Ki1 ≤ Ki2 ≤… ≤ Kin.    (Or Ki1 ≥ Ki2 ≥… ≥ Kin). 

  Here, we briefly introduce some sort, direct insertion sort, the Greek infants sort, Bubble Sort, quick sort, direct selection sort, and mentioned in the text of the code under test in IE6 through. 

  Direct insertion sort Basic idea 

  Hypothetical question to sort the records stored in an array of R [1 .. n].    Initial, R [1] Since the district into an orderly and disorderly District R [2 .. n].    2 from i = i = n up to date, followed by R [i] will be inserted into the current orderly District R [1 .. i-1], the formation of the n records orderly District. 

  Algorithm description 

  Function InsertSort (arr) (/ / insert sort -> direct insertion sort 
  Var st = new Date (); 
  Var temp, j; 
  For (var i = 1; i <arr.length; i) ( 
  If ((arr [i]) <(arr [i-1])) ( 
  Temp = arr [i]; 
  J = i-1; 
  Do ( 
  Arr [j 1] [j] = arr; 
  J -; 
  ) 
  While (j> -1 & & (temp) <(arr [j])); 
  Arr [j 1] = temp; 
  ) / / Endif 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 

  Hill basic idea of sort 

  First take an integer n is less than d1, as a first increment, the documents of all the records into d1 group.    Dl distance of all the multiples of record on the same group.    In the first group of people to order directly from then, from the second increment d2 <d1 repeat the sort of Grouping and until the incremental admitted dt = 1 (dt <dt-l <… < d2 <d1), which are all on record in the same group for direct sequencing of the insert. 
  The method is essentially a packet insertion methods. 

  Algorithm description 

  Function ShellSort (arr) (/ / insert sort -> Mariji sort 
  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) (/ / sub Mariji sort Executive Function 
  Var temp, j; 
  For (var i = d; i <arr.length; i) ( 
  If ((arr [i]) <(arr [id])) ( 
  Temp = arr [i]; j = id; 
  Do ( 
  Arr [jd] = arr [j]; 
  Jd = j; 
  ) 
  While (j> -1 & & (temp) <(arr [j])); 
  Arr [jd] = temp; 
  ) / / Endif 
  ) 
  Return arr; 
  ) 

  Bubble Sort basic idea 

  Will be to sort the records array R [1 .. n] vertical array, each recorded R [i] as a weight for R [i]. Key bubbles.    According to light in the not-bubble bubble under the principle of scanning array from the Bottom up R: Where to scan violation of the principles of the bubble light on its upward "floating."    So repeatedly, until the last two bubbles are any in the light, heavy, the next date. 


  Algorithm description 

  Function BubbleSort (arr) (/ / exchange sort -> Bubble Sort 
  Var st = new Date (); 
  Var temp; 
  Var exchange; 
  For (var i = 0; i <arr.length; i) ( 
  Exchange = false; 
  For (var j = arr.length-2; j> = i; j -) ( 
  If ((arr [j 1]) <(arr [j])) ( 
  Temp = arr [j 1]; 
  Arr [j 1] [j] = arr; 
  Arr [j] = temp; 
  Exchange = true; 
  ) 
  ) 
  If (! Exchange) break; 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 

  Quick Sort basic idea 

  Decomposition of the original problem for a number of smaller-scale but similar to the original question of the sub-problems.    Recursive solutions to these sub-problems, then the solution of these problems of the original composition of the solution. 
  In the R [low .. high] Choose a record as the benchmark (Pivot), as the current benchmark disorderly divided into left and right two smaller sub-interval R [low .. pivotpos-1) and R [ pivotpos 1 .. high], and left all records in the range of keywords are less than or equal to benchmark records (recorded as may pivot) pivot.key keywords, the right of all records in the range of keywords are more than pivot.key equivalent, and the base record pivot is located in the correct Position (pivotpos), it is not required to participate in follow-up sort. 

  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 <high) ( 
  / / Function Partition 
  Var i = low; 
  Var j = high; 
  Var pivot = arr [i]; 
  While (i <j) ( 
  While (i <j && arr[j]> = pivot) 
  J -; 
  If (i <j) 
  Arr = arr [i] [j]; 
  While (i <j & arr [i] <= pivot) 
  I; 
  If (i <j) 
  Arr [j -] = arr [i]; 
  ) / / Endwhile 
  Arr [i] = pivot; 
  / / End function 
  Var pivotpos = i; / / Partition (arr, low, high); 
  QuickSort (arr, low, pivotpos-1); 
  QuickSort (arr, pivotpos 1, high); 
  ) Else 
  Return; 
  Return arr; 
  ) 

  Sort basic idea of direct selection 

  N Records of the document can be directly choose to sort through n-1 trip in an orderly manner by direct sequencing options: 
  ① initial state: disorderly District R [1 .. n], and orderly area is empty. 
  ② No. 1 ranking in times of disorder District R [1 .. n] selected keyword smallest recorded R [k], it will be the first and disorderly a record R [1] exchange, the R [1 .. 1] and R [2 .. n] increase in the number of records were turned into a new area in an orderly manner and to reduce a record number of new areas of disorder. 
……
  ③ The first sort i times i sort trips at the beginning of the current district and orderly disorder zones respectively R [1 .. i-1] and R [i.. N] (1 ≤ i ≤ n-1) .    The trip from the current sort of disorder in the area selected keyword smallest recorded R [k], it will be the first and disorderly a record R [i] exchange, the R [1 .. i] and R [i 1 .. n] increase in the number of records were turned into a new area in an orderly manner and to reduce a record number of new areas of disorder. 
  Thus, n records of documents directly choose to sort through n-1 can directly choose trip to sort results by orderly. 

  Algorithm description 

  Function SelectSort (arr) (/ / sorting options -> direct sequencing choice 
  Var st = new Date (); 
  Var temp; 
  For (var i = 0; i <arr.length; i) ( 
  Var k = i; 
  For (i var j = 1; j <arr.length; j) ( 
  If ((arr [j]) <(arr [k])) 
  K = j; 
  ) 
  If (k! = I) ( 
  Temp = arr [i]; 
  Arr [i] = arr [k]; 
  Arr [k] = temp; 
  ) 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 


<style>
  Fieldset ( 
  Font-size: 12px; 
  Padding: 10px; 
  Width: 80%; 
  Margin: auto; 
  ) 
  Input ( 
  Font-size: 12px; 
  Font-family: Tahoma; 
  ) 
  </ Style> 
  <title> Sort </ title> <h3 align="center"> sort </ h3> <fieldset> 
  <legend> Insertion sort </ legend> <p> <b> direct insertion sort </ b> 
  Please enter a period to sort the characters, separated by a comma-byte characters 
  <input Name=insert type=text size=100 value="g,v,u,f,p,o,i,a,t,j,e,l,k"> 
  <br> <input Type=button value="排序" onclick="alert(InsertSort(insert.value.split(',')));"> <p> <b> Mariji sort </ b> <br> <input name=Shell type=text size=100 value="g,v,u,f,p,o,i,a,t,j"> 
  <br> <input Type=button value="排序" onclick="alert(ShellSort(Shell.value.split(',')));"> </ fieldset> <p> <fieldset> <legend> exchange Sort </ legend> <b> Bubble Sort </ b> <br> 
  <input Name=bubble type=text size=100 value="g,v,u,f,p,o,i,a,t,j,e,l,k"> 
  <br> <input Type=button value="排序" onclick="alert(BubbleSort(bubble.value.split(',')));"> <p> <b> Quick Sort <br> </ b> <input name=quick type=text size=100 value="3,1,5,4,6"> 
  <br> <input Type=button value="排序" onclick="alert(QuickSortDemo(quick.value.split(',')));"> </ fieldset> <p> <fieldset> 
  <legend> Choose sort </ legend> <b> direct selection sort </ b> <br> 
  <input Name=select1 type=text size=100 value="g,v,u,f,p,o,i,a,t,j,e,l,k"> 
  <br> <input Type=button value="排序" onclick="alert(SelectSort(select1.value.split(',')));"> <p> ... ... </ fieldset> < script> 
  Function InsertSort (arr) (/ / insert sort -> direct insertion sort 
  Var st = new Date (); 
  Var temp, j; 
  For (var i = 1; i <arr.length; i) ( 
  If ((arr [i]) <(arr [i-1])) ( 
  Temp = arr [i]; 
  J = i-1; 
  Do ( 
  Arr [j 1] [j] = arr; 
  J -; 
  ) 
  While (j> -1 & & (temp) <(arr [j])); 
  Arr [j 1] = temp; 
  ) / / Endif 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 

  Function ShellSort (arr) (/ / insert sort -> Mariji sort 
  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) (/ / sub Mariji sort Executive Function 
  Var temp, j; 
  For (var i = d; i <arr.length; i) ( 
  If ((arr [i]) <(arr [id])) ( 
  Temp = arr [i]; j = id; 
  Do ( 
  Arr [jd] = arr [j]; 
  Jd = j; 
  ) 
  While (j> -1 & & (temp) <(arr [j])); 
  Arr [jd] = temp; 
  ) / / Endif 
  ) 
  Return arr; 
  ) 

  Function BubbleSort (arr) (/ / exchange sort -> Bubble Sort 
  Var st = new Date (); 
  Var temp; 
  Var exchange; 
  For (var i = 0; i <arr.length; i) ( 
  Exchange = false; 
  For (var j = arr.length-2; j> = i; j -) ( 
  If ((arr [j 1]) <(arr [j])) ( 
  Temp = arr [j 1]; 
  Arr [j 1] [j] = arr; 
  Arr [j] = temp; 
  Exchange = true; 
  ) 
  ) 
  If (! Exchange) break; 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 

  Function QuickSortDemo (arr) ( 
  Var st = new Date (); 
  Var result = QuickSort (arr); 
  Status = (new Date () - st) 'ms'; 
  Return result; 
  ) 

  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 <high) ( 
  / / Function Partition 
  Var i = low; 
  Var j = high; 
  Var pivot = arr [i]; 
  While (i <j) ( 
  While (i <j && arr[j]> = pivot) 
  J -; 
  If (i <j) 
  Arr = arr [i] [j]; 
  While (i <j & arr [i] <= pivot) 
  I; 
  If (i <j) 
  Arr [j -] = arr [i]; 
  ) / / Endwhile 
  Arr [i] = pivot; 
  / / End function 
  Var pivotpos = i; / / Partition (arr, low, high); 
  QuickSort (arr, low, pivotpos-1); 
  QuickSort (arr, pivotpos 1, high); 
  ) Else 
  Return; 
  Return arr; 
  ) 

  / * Function Partition (arr, i, j) (/ / Quick Sort treat sort array of 
  Var pivot = arr [i]; 
  While (i <j) ( 
  While (arr [j]> = pivot) 
  J -; 
  If (i <j) 
  Arr = arr [i] [j]; 
  While (arr [i] <= pivot) 
  I; 
  If (i <j) 
  Arr [j -] = arr [i]; 
  ) 
  Arr [i] = pivot; 
  Return arr; 
  ) * / 

  Function SelectSort (arr) (/ / sorting options -> direct sequencing choice 
  Var st = new Date (); 
  Var temp; 
  For (var i = 0; i <arr.length; i) ( 
  Var k = i; 
  For (i var j = 1; j <arr.length; j) ( 
  If ((arr [j]) <(arr [k])) 
  K = j; 
  ) 
  If (k! = I) ( 
  Temp = arr [i]; 
  Arr [i] = arr [k]; 
  Arr [k] = temp; 
  ) 
  ) 
  Status = (new Date () - st) 'ms'; 
  Return arr; 
  ) 

  Function unicode (str) (/ / string for the code unicode 
  Var uni = 0; 
  For (var i = 0; i <str.length; i) ( 
  Uni = str.charCodeAt (i) / 6553.5 * Math.pow (10, str.length-i); 
  ) 
  Return uni; 
  ) 
  </ Script> 

Related articles:

DIV center - the issue of medium
  <Div style = "border: a solid red; position: absolute; top: expression ((this.parentElement.offsetHeight-this.offsetHeight) / 2); left: expression ((this.parentElement.offsetWidth-this.offsetWidth) / 2); "> I stand by the center <br> </ div>    </ Di...
Film Import Control
  1, prohibit into film, writing in the first-ching on root._name _ = "nn";    This.onEnterFrame = function () (    If (this._name! = "Nn" | | _root.getDepth ()! = -16384) (    This.unloadMovie ();    )    );  &nbs...
CSS is a link or document should be embedded?
  CSS style sheet document is used to link separate document called a good thing, or the direct use of <style >......</ style> embedded within the pages well?    Or to say how the two methods used?    W3cn the Ajie said that in the past, we usually use two kind...
Construction of the whole Blog Dreamweaver Record (3): database design and connectivity
  Construction of a good development environment, Doking's BLOG database planning is the third step, it is also directly related to the database after the effective operation of the key steps, as well as a database developer is the norm.    3.1 Data Base    Database N...
Flash 8.0 Guide: dynamic fuzzy results
  Drilled to a flash8 tonight, I feel quite good drop, I read a lot of online flash8 the effects, unfortunately many of them will not do so, the main idea is not just practicing to blur filters, their hands a blur effects Dynamic I feel pretty good that the code is too simple to write somethin...