#include void swap_if(int & x, int & y) // if x <= y, leave them alone, do nothing // if x > y, swap them { if (x > y) { int temp = x; x = y; y = temp; } } void main() { int A[10]; ifstream fin; fin.open("data"); if (fin.fail()) { cout << "Can't find file\n"; exit(1); } int i = 0; while (i <= 9) { fin >> A[i]; i = i + 1; } if (fin.fail()) { cout << "bad data or not enough data\n"; exit(1); } fin.close(); int line = 8; while (line >= 0) { i = 0; while (i <= line) { swap_if(A[i], A[i+1]); i = i + 1; } line = line - 1; } i = 0; while (i <= 9) { cout << A[i] << " "; i = i + 1; } cout << "\n"; }