选择排序
来源:互联网 发布:mac 符号 编辑:程序博客网 时间:2024/05/17 05:11
class Sort
{
public static void main(String[] args)
{
int[] arr={5,1,6,4,2,8,9};
printArray(arr);//先按原顺序输出一次
selectSort(arr);//调用函数
printArray(arr);//排序后在输出一次
}
public static void selectSort(int[] arr)//定义排序函数
{
for (int x=0;x<arr.length-1 ;x++ )
{
for (int y=x+1;y<arr.length ;y++ )
{
if (arr[x]>arr[y])
{
int temp=arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
}
}
}
public static void printArray(int[] arr)//定义输出函数
{
System.out.print("[");
for (int x=0;x<arr.length ; x++)
{
if(x!=arr.length-1)
System.out.print(arr[x]+", ");
else
System.out.println(arr[x]+"]");
}
}
}
{
public static void main(String[] args)
{
int[] arr={5,1,6,4,2,8,9};
printArray(arr);//先按原顺序输出一次
selectSort(arr);//调用函数
printArray(arr);//排序后在输出一次
}
public static void selectSort(int[] arr)//定义排序函数
{
for (int x=0;x<arr.length-1 ;x++ )
{
for (int y=x+1;y<arr.length ;y++ )
{
if (arr[x]>arr[y])
{
int temp=arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
}
}
}
public static void printArray(int[] arr)//定义输出函数
{
System.out.print("[");
for (int x=0;x<arr.length ; x++)
{
if(x!=arr.length-1)
System.out.print(arr[x]+", ");
else
System.out.println(arr[x]+"]");
}
}
}
0 0
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序:
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- 选择排序
- PHP生成唯一订单号
- ubuntu下安装oracle jdk方法
- [BZOJ1603] [Usaco2008 Oct]打谷机
- Java中内存泄露及垃圾回收机制
- HDU oj 今年暑假不AC 题目2037
- 选择排序
- hdu1231 最大连续子序列
- 修改文件所属组和用户
- 平安城市之治安监控摄像机
- iOS_导入libxml2.2框架后,找不到<libxml/tree.h>的解决办
- 算法导论——(1)加权中位数的实现
- WPF使用DEV之TreeListControl---添加数据
- 2015-7-22随笔
- atexit()函数来注册程序正常终止时被调用的函数