Data Structures & Algorithms Lecture Notes

13 April 2010 • Sorting Basics


static public void 
bubbleSort(int a[]) {

  // Re-arrange the array elements a[0..n-1] 
  // so they are in ascending order.

  for (int i = 0; i < a.length - 1; i++)
    for (int min = a.length - 1; min > i; min--)
      if (a[min - 1] > a[min]) {
	final int t = a[min - 1];
	a[min - 1] = a[min];
	a[min] = t;
	}
  }


This page last modified on 24 January 2006.