bubbleSort static method

List bubbleSort(
  1. List list
)

Implementation of the bubble sort algorithm

Implementation

static List bubbleSort(List list) {
  var retList = List.from(list);
  var tmp;
  var swapped = false;
  do {
    swapped = false;
    for (var i = 1; i < retList.length; i++) {
      if (retList[i - 1].compareTo(retList[i]) > 0) {
        tmp = retList[i - 1];
        retList[i - 1] = retList[i];
        retList[i] = tmp;
        swapped = true;
      }
    }
  } while (swapped);

  return retList;
}