Java 这是选择排序算法吗?这是冒泡排序 。
下面是选择排序选择排序代码java的代码选择排序代码java:
for(int i=0;ia.length;i++){
max = i;
/**查找第 i大的数选择排序代码java,直到记下第 i大数的位置***/
for(int j=i+1;ja.length;j++){
if(a[max]a[j])
max = j;//记下较大数位置选择排序代码java,再次比较选择排序代码java,直到最大
}
/***如果第 i大数的位置不在 i,则交换****/
if(i!=max){
tmp = a[i];
a[i] = a[max];
a[max] = tmp;
}
}
直接选择排序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;
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( );
推荐阅读
- 姗姗直播录屏怎么录屏的,姗姗直播录屏怎么录屏的啊
- css中空格符号的代码,css空格符号怎么打
- 想自己做电商如何开始,怎样去做电商
- 抖音小黄车如何做推广,抖音小黄车如何做推广
- linuxps命令参数 linux中ps命令的用法
- jquery截图添加文字,jquery截取特定字符
- net4.0怎么会安装为成功,net 462安装不成功
- ar飞行游戏设备开箱,air飞行模拟游戏
- mysql的不等号怎么写 mysql中不等于怎么写