You are here: Home Exercises Additional Material … Sort.java

Sort.java

Plain Text icon Sort.java — Plain Text, 291 bytes

File contents

class Sort {

  static int[] sort(int[] a) {
    for (int j = a.length - 1; j > 0; j--) {
      for (int i = 0; i < j; i++) {
        if (a[i] > a[i+1]) {
          int tmp = a[i];
          a[i] = a[i+1];
          a[i+1] = tmp;
        }
      }
    }
    return a;
  }

}