插入排序(捂脸><这个写的不对)

import java.util.Arrays;

/*
 * Created on 2012-3-12
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author hongbin.mu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Px {
	private int[] array;
	
	/**
	 * @return Returns the array.
	 */
	public int[] getArray() {
		return array;
	}
	/**
	 * @param array The array to set.
	 */
	public void setArray(int[] array) {
		this.array = array;
	}
	public Px(int[] array){
		this.array=array;
	}
	
	public void sort(){
		 for(int i=1;i<array.length;i++){
		 	if(array[i]!=0){
		 	int k=i;
		 	while(k>0){
		 		if(array[k]<array[k-1]){
		 			int temp = array[k];
		 			array[k]=array[k-1];
		 			array[k-1]=temp;
		 		}else{
		 			break;
		 		}
		 		k--;
		 	}
		 }
		 }
		 
	}
	
	public static void main(String[] args) {
		Array ars= new Array(10,8);
		Px px= new Px(ars.getArray());
		px.sort();
	
		System.out.println(Arrays.toString(px.getArray()) );
	}
	
	
	
}

 

/*
 * Created on 2012-3-12
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author hongbin.mu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Array {
	private int[] array;
	
	/**
	 * @return Returns the array.
	 */
	public int[] getArray() {
		return array;
	}
	/**
	 * @param array The array to set.
	 */
	public void setArray(int[] array) {
		this.array = array;
	}
	public Array(int cout,int num){
		array=new int[cout];
		for(int i=0;i<num;i++){
			array[i]=(int)(Math.random()*100);
//			System.out.println(array[i]);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值