You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Learn/Jb23_ArrTool.java

77 lines
1.4 KiB

/**
<EFBFBD>ĵ<EFBFBD>ע<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><EFBFBD><EFBFBD>
@author XiaoMing
@version V1.0
*/
public class Jb23_ArrTool
{
/*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD>̬<EFBFBD>ģ<EFBFBD><EFBFBD≯<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬽<EFBFBD>ʡ<EFBFBD>ڴ<EFBFBD>
Ϊ<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򴴽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
private Jb23_ArrTool(){}
/**<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
@param arr <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>Ϊint<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ֵ*/
public static int getMax(int[] arr)
{
int maxIndex = 0;
for (int x=1;x<arr.length ;x++ )
{
if (arr[x]>arr[maxIndex])
{
arr[maxIndex] = arr[x];
}
}
return arr[maxIndex];
}
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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])
{
swap(arr,x,y);
}
}
}
}
//<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD>ص<EFBFBD>λ<EFBFBD>û<EFBFBD>λ
public static void swap (int[] arr,int x,int y)
{
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
//<2F><>ȡָ<C8A1><D6B8>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĽDZ꣬<C7B1><EAA3AC><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>-1
public static int getIndex(int[] arr,int key)
{
for (int x=0;x<arr.length ;x++ )
{
if (arr[x]==key)
{
return x;
}
}
return -1;
}
//<2F><>int<6E><74><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
public static String arrayToString(int[] arr)
{
String s = "";
for (int x=0; x<arr.length;x++ )
{
if (x!=arr.length-1)
s = s + arr[x]+",";
else
s = s + arr[x];
}
return s;
}
}