Data on the structure of the four types of simple sorting algorithm.

  Abstract: Data on the structure of the four kinds of simple sorting algorithm. 

  </ Td> </ tr> <tr> <td width="491" height="35" valign="top" class="ArticleTeitle"> / / data structure on the four kinds of simple sorting algorithm. 
  / ** 
*

Title:
*

Description:

*

  Copyright: Copyright (c) 2005 

*

Company:

  * @ Author Zhongweihai 
  * @ Version 1.0 
  * / 

  Public class Sort (public Sort () () int [] s = () 12,4,56,44,3,34,32,2,5,21; int a = 10; / / 1, insert the sort ( Pai Tau first two elements of the sequence, then the first three elements of the row sequence ……) public void insort () (int in, out; for (out = 1; out <a; out + +) (int temp = s [out]; in = out; while (in> 0 & & s [in-1]> = temp) (s = s [in] [in-1]; - in;) s [in] = temp;) for ( int j = 0; j <a; j + +) (System.out.println (j +"="+ s [j]);)) / / 2, select sort (first round, each of the first number , the smallest number of ,…) become the first public void selectSort () (int out, in, min; for (out = 0; out <a-1; out + +) (min = out; for (out in = +1; in <a; in + +) (if (s [in] <s [min]) swap (in, min);)) for (int j = 0; j <a; j + +) (System.out.println (j +"="+ s [j]);)) / / 3, Bubble Sort public void bubbleSort () (int out, in; for (out = a-1; out> 1; out -) ( for (in = 0; in <out; in + +) (if (s [in] +1> s [in]) (swap (in, in +1);))) for (int j = 0; j <a ; j + +) (System.out.println (j +"="+ s [j]);)) private void swap (int one, int two) (int temp = s [one] s [one] = s [two ;] s [two] = temp;) public static void main (String [] args) = (Sort in new Sort (); / / in.insort (); in.selectSort (); / / in.bubbleSort () ;)) 4, quick sort of precedence in the middle element of the array, and the array is divided into two smaller array, an array containing only greater than the median value of the element, while another array containing only less than the median elements, repeat the process.    Public class arrayQsort (static void qsort (int array [], int first, int last) (int low = first; = int high last; if (first> = last) return; int mid = array [(first last +) / 2]; do (while (array [low] <mid) low + +; while (array [high]> mid) high -; if (low <= high) (int temp = array [low]; array [low + +] = array [high]; array [high -] = temp;)) while (low <= high); qsort (array, first, high); qsort (array, low, last);) public static void main (String [ ] args) (int [] s = () 12,4,56,44,3,34,32,2,5,21; qsort (s, 0,9); for (int j = 0; j <10 ; j + +) (System.out.println (j +"="+ s [j]);))) 

  Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) 

  Procedures for the operation of the results: 

  C: \ java> java Sort 
  0 = 2 
  1 = 3 
  2 = 4 
  3 = 5 
  4 = 12 
  5 = 21 
  6 = 32 
  7 = 34 
  8 = 44 
  9 = 56 

  C: \ java> java arrayQsort 
  0 = 2 
  1 = 3 
  2 = 4 
  3 = 5 
  4 = 12 
  5 = 21 
  6 = 32 
  7 = 34 
  8 = 44 
  9 = 56 

  C: \ java> 

  </ Td> <td width="193" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply