# C++: Bubblesort Fill-in Questions

Name _______________________________

(5 points) Fill in each blank with a single missing element (operator, keyword, variable, literal, ...).

## Bubble Sort -- stop when no exchanges, shorter range each time

This version of bubble sort stops when there are no more exchanges, and it also sorts a smaller range each time.

    void bubbleSort3(int x[], int n) {
      bool _____________;
      do {
        n--;               // make loop smaller each time.
        exchanges = false; // assume this is last pass over array
        for (int i=0; i<n; i++) {
          if (x[i] > x[i+1]) {
            int temp = x[_____________];  x[i] = x[i+1];  x[i+1] = _____________;
            exchanges = _____________;  // after an exchange, must look again
          }
        }
      } while (_____________);
    }