java选择性排序代码 java选择性排序代码怎么写

求java选择排序代码及注释//简单选择排序,按自然顺序
public static void selectsort(int[] array){
int min, index, temp;
for(int i = 0; iarray.length - 1; i++){// N - 1 趟
min = i;
//查找选择最小元素值的下标索引值
for(index = i + 1; indexarray.length; index++){
if(array[min]array[index])
min = index;
}
//交换
if(min != i){
temp = array[min];
array[min] = array[i];
array[i] = temp;
}
}
}
直接选择排序Java实现 About this application:
This application implements Straight Selection Sort algorithm which is described like this:
If there are N numbers find the minimum and exchange it with the first number then N numbers remained Continue to find the minimum number in the remained N numbers and exchange it with the second number Repeat this until all the numbers are in order
Note: This is SWT application so you need eclipse swt win win x _ v b jar eclipse jface_ I jar mands_ I jar This is for Eclipse
Source Code:
package selection sort;
import java util ArrayList;
import eclipse swt SWT;
import eclipse swt events KeyAdapter;
import eclipse swt events KeyEvent;
import eclipse swt events ModifyEvent;
import eclipse swt events ModifyListener;
import eclipse swt events SelectionAdapter;
import eclipse swt events SelectionEvent;
import eclipse swt layout FormAttachment;
import eclipse swt layout FormData;
【java选择性排序代码 java选择性排序代码怎么写】 import eclipse swt layout FormLayout;
import eclipse swt widgets Button;
import eclipse swt widgets Display;
import eclipse swt widgets Group;
import eclipse swt widgets Label;
import eclipse swt widgets Shell;
import eclipse swt widgets Text;
/**
* This application implements Straight Selection Sort algorithm which means
* get the minimum number from the numbers and exchange it with the first
* number then doing this for other numbers except the first number Repeat
* this until all numbers are in order If you have any suggestion or problem
* please e mail to
*
* @author vivien Data:
*/
public class StraightSelectionSort {
/** The string containing the number wait for sorted */
public String numString = new String();
public Text numText;
public Text resText;
public Button btSort;
public Label errorLabel;
/** The flag to indicate if there is any error for inputed numbers */
public boolean hasError = false;
/** The arrayList containing the double numbers wait for sorted */
public ArrayListDouble numList = new ArrayListDouble();
public static void main(String[] args) {
StraightSelectionSort selectionSort = new StraightSelectionSort();
selectionSort createControl();
}
/**
* Create the control for the interface
*/
public void createControl() {
Display display = new Display();
Shell shell = new Shell(display);
shell setBounds( );
// Set Title
shell setText( Straight selection sort );
FormLayout layout = new FormLayout();
shell setLayout(layout);
FormData fd = new FormData();
// The Start Sort button
btSort = new Button(shell SWT NONE | SWT CENTER);
btSort setText( Start Sort );
fd = new FormData();
fd height = ;
fd top = new FormAttachment( );
fd left = new FormAttachment( );
btSort setLayoutData(fd);
// The Input numbers group
Group numGroup = new Group(shell SWT NONE);
numGroup setText( Input numbers: );
numGroup setLayout(layout);
fd = new FormData();
fd top = new FormAttachment( );
fd left = new FormAttachment( );
fd right = new FormAttachment( );

推荐阅读