简单排序和输出

Posted agzno1hb

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单排序和输出相关的知识,希望对你有一定的参考价值。

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]+" ]");
}
}

}

以上是关于简单排序和输出的主要内容,如果未能解决你的问题,请参考以下文章

简单选择排序法

treemap反序输出 逆序输出 输出倒数几个值

排序1-简单选择排序

拓扑排序(图)、冒泡排序、插入排序

我想写一个简单的shell脚本,来将我的源文件中的每行进行排序输出,

排序?排序!