博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单排序和输出
阅读量:6962 次
发布时间:2019-06-27

本文共 979 字,大约阅读时间需要 3 分钟。

class ArrayTool

{
//最大值
public static int getMax(int[] arr)
{
int max=0;
for (int x=0;x<arr.length ;x++ )
{
if (arr[x]>arr[max])
{
max =x;
}
}
return arr[max];
}
//最小值
public static int getMin(int[] arr)
{
int min=0;
for (int x=0;x<arr.length ;x++ )
{
if (arr[x]<arr[min])
{
min =x;
}
}
return arr[min];
}

//选择排序
public void selectSort(int[] arr)
{
for (int x =0;x<arr.length ;x++ )
{
for (int y=x+1;y<arr.length ;y++ )
{
if (arr[x]>arr[y])
{
swap(arr,x,y);
}
}
}
}
//冒泡排序
public void bubbleSort(int[] arr)
{
for (int x=0;x<arr.length-1 ;x++ )
{
for (int y=0;y<arr.length-x-1 ;y++ )
{
if (arr[y]>arr[y+1])
{
swap(arr,y,y+1);
}
}
}
}
///交换.
public void swap(int[] arr,int a,int b )
{
int temp =arr[a];
arr[a]=arr[b];
arr[b]=temp;
}
//输出.
public 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]+" ]");
}
}

}

转载于:https://www.cnblogs.com/agzno1hb/p/9092905.html

你可能感兴趣的文章
数据库模型设计——关系的实现,主键的设计
查看>>
webistrano的安装方法和一些用法
查看>>
Memcache集群高可用方案
查看>>
mysql数据据存储引擎InnoDB和MyISAM的优势及区别
查看>>
PowerShell中iso8601格式日期和DateTime对象互转实例
查看>>
MySQL Cluster, Fabric, Cobar 三大集群特性对比
查看>>
SpringBoot(八):测试组件-junit
查看>>
Mysql命令
查看>>
使用chmod命令改变权限
查看>>
java程序使用cmd备份和恢复数据库
查看>>
item点击变色
查看>>
tomcat的配置及负载均衡
查看>>
android基本控件及表单(3)
查看>>
Sharepoint多站点通过apache进行多域名访问
查看>>
Windows Azure 安全控制-ACL
查看>>
linux vsftp配置大全—超完整版
查看>>
ActionBar的移除与显示
查看>>
MySQL 报错
查看>>
数据库启停标准操作流程
查看>>
Mac不能快速传输文件的原因你知道么
查看>>