#include "stdstuff.h" int main () { const int MAXVALUES = 100, TERMINATOR = -1; int data [MAXVALUES], count, value, i, temp, stop; cout << "\nEnter up to " << MAXVALUES << " values followed by " << TERMINATOR << ": "; count = 0; for (;;) { cin >> value; if (value == TERMINATOR) { // the input process is complete break; } if (count == MAXVALUES) { // the array is full cout << "\nToo many values entered.\n"; pause(); return 0; } data[count++] = value; } bool swapOccurred; stop = count - 1; // on the first pass “i” must be < “count – 1” do { // make a pass swapOccurred = false; // no interchanges so far on this pass for (i = 0; i < stop; i++) { if (data[i] > data[i + 1]) { // if elements are out of order // interchange elements temp = data[i]; data[i] = data[i + 1]; data[i + 1] = temp; swapOccurred = true; } } stop--; // on the next pass, stop one comparison sooner } while (swapOccurred); if (count == 0) { cout << "\nNo values were entered.\n"; } else { cout << "\nThe values in order are:\n"; for (i = 0; i < count; i++) { cout << " " << data[i] << endl; } } pause(); return 0; }