选择排序法
来源:互联网 发布:网络金融征信系统 编辑:程序博客网 时间:2024/06/06 00:26
public class TestNumSort {
public static void main(String[] args) {
int[] a = {5, 7, 4, 6, 2, 9, 8, 1, 3, 10};
TestNumSort test = new TestNumSort(); //记得创建一个对象,才可以调用之后的方法
test.Print(a);
test.NumSortSolution(a);
test.Print(a);
}
private void Print(int[] num) { //输出num数组中的所有元素
for(int temp : num) {
System.out.print(temp + " ");
}
System.out.println();
}
private void NumSortSolution (int[] num) { //选择排序法
int k,j;
for(int i = 0; i < num.length-1; i++ ) {
k = i;
for(j = i + 1; j < num.length; j++)
if(num[j] > num[k]) k = j;
int t = num[k];
num[k] = num[i];
num[i] = t;
}
}
}
public static void main(String[] args) {
int[] a = {5, 7, 4, 6, 2, 9, 8, 1, 3, 10};
TestNumSort test = new TestNumSort(); //记得创建一个对象,才可以调用之后的方法
test.Print(a);
test.NumSortSolution(a);
test.Print(a);
}
private void Print(int[] num) { //输出num数组中的所有元素
for(int temp : num) {
System.out.print(temp + " ");
}
System.out.println();
}
private void NumSortSolution (int[] num) { //选择排序法
int k,j;
for(int i = 0; i < num.length-1; i++ ) {
k = i;
for(j = i + 1; j < num.length; j++)
if(num[j] > num[k]) k = j;
int t = num[k];
num[k] = num[i];
num[i] = t;
}
}
}
0 0
- 常用排序-选择法排序
- 常见排序-选择法排序
- 排序算法--选择排序法
- 按选择排序法排序。
- 排序模板 选择法排序
- 排序算法--选择排序法
- 排序之选择排序法
- 选择排序法法
- 排序:选择法
- 选择排序法
- 选择法排序
- 选择排序法
- 选择排序法证明
- 选择排序法
- 选择排序法
- 选择排序法
- 选择排序法
- C++ 选择排序法
- 《Neural networks and deep learning》概览
- netfilter 概要
- Linux进程地址空间 && 进程内存布局
- 【华为OJ】找出字符串中第一个只出现一次的字符
- Linux修改ip地址
- 选择排序法
- android客户端提交数据到服务器中文乱码三种解决方案
- 开启ubuntu下lamp的php错误提示
- Get与Post区别与范例讲解
- DeepLearnToolbox使用总结
- 【iOS开发quartz2d】关于图形上下文栈
- 【二值化】sauvola算法实现
- 关于Oracle创建表空间,用户名登录问题
- 以后每天开始写自己的博客----Start