`
tanglei198577
  • 浏览: 57696 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

Bubble Sort - The arithmetic always queried by interviewer

    博客分类:
  • java
J# 
阅读更多
/**
 * 
 * @author tanglei
 * @since  07.27
 */

public class MaoPao {
	public static void main(String[] args){
	    int a[] = {5,4,3,2,1} ;
	    for(int i=0;i<a.length;i++)
	    { 
	       for(int j=0;j<a.length-i-1;j++)
	       {
	          int temp;
	          if(a[j]>a[j+1])
	          {
	             temp  = a[j];
	             a[j] = a[j+1];
	             a[j+1]  = temp;
	          }
	       }    
	    }
	    for(int k=0;k<a.length;k++)
	    {
	    	 System.out.println(a[k]);
	    }
	}

}

    Output :

                   1

                   2

                   3

                   4

                   5

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics