`

选择排序java实现

阅读更多
/**
选择排序
* @author leader
* 2009-11-3
*/
class Array
{
public static int maxsize ;//数组的长度的最大值
public static int realsize;
int [] array ;//数组
public Array (int maxsize)
{
//初始化这个类
this.maxsize  = maxsize;
this.array = new int [this.maxsize];
this.realsize = 0 ;
}
/**
* 给数组添加数据 不排序
*/
public void insert (int ins)
{
array[this.realsize]=ins;
this.realsize++;
}

/**
用选择排序给数组排序
2009-11-3
*/
public void bubble ()
{
int temp;
for (int i=0 ;i<this.realsize ;i++ )
{
for (int j =i+1; j<this.realsize ; j++)
{
if(array[i]>array[j])
{
temp = array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
}
/**
* 数组的大小只是给人看的
* @return
*/
public int size ()
{
return this.realsize;
}
public void display ()
{
for (int i = 0 ;i<this.realsize;i++)
{
System.out.println(array[i]);
}
}
public void delete (int del)
{
int i = 0;
for ( ;i<this.realsize;i++)
{
if(array[i]==del)
{
break;
}

}
for(int j = i;j<this.realsize;j++)
{
array[j]=array[j+1];
}
this.realsize--;
}

}
public class Chape {
public static void main(String[] args) {
Array array = new Array(100);
array.insert(1);
array.insert(9);
array.insert(3);
array.insert(5);
array.insert(0);

array.display();
System.out.println("我是分割线----------------------------------");
array.bubble();
array.display();
System.out.println("数组长度"+array.size());



}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics