排序-冒泡排序
public class PaiXu {
/**
* @方法描述:<p></p>
* @返回值:void
* @author:WS @日期:2009-5-9
*/
static int[] list = new int[]{1,3,2,5,7,9,4,3,39,6};
public static void main(String[] args) {
PaiXu px = new PaiXu();
px.maoPao(list);
px.print(list);
System.out.println("/n索引值:"+px.indexof(list, 9));
}
public void print(int[] list)
{
for(int num :list)
{
System.out.print(num+",");
}
}
//小的数据往上排
public int[] maoPao(int[] list)
{
for(int i=0;i<list.length-1;i++) //外层循环
{
for(int j=0;j<list.length-i-1;j++) //内层循环
{
if(list[j]>list[j+1])
{
int temp = list[j];
list[j] = list[j+1];
list[j+1] = temp;
}
}
}
return list;
}
public int indexof(int[] list,int value)
{
for(int i=0;i<list.length;i++)
{
if(list[i]==value)
return i;
}
return -1;
}
}