中央論壇 - CENTER BBS

標題: Bubble sort method [打印本頁]

作者: f66666602    時間: 2007-7-27 21:09
標題: Bubble sort method
public class BubbleSort { //ClassName and FileName:BubbleSort
  public static void main(String args[]) {
    short source[] = {
        540, 94, 458, 47, 64}; //source
    short exchange = 0;
    for (short pass = 1; pass < source.length; pass++) {
      for (short i = 0; i < source.length - 1; i++) {
        if (source > source[i + 1]) {
          exchange = source; //swap
          source = source[i + 1];
          source[i + 1] = exchange;
        } // if end
      } //for end
    } //for end
    for (short i = 0; i < source.length; i++) {
      System.out.print(source + " "); //show result on screen
    }
  } //main method end
} //class end




歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/) Powered by Discuz! X3