#include #include #include using namespace std; void display(const vector& v, ostream& os = cout); void display(const vector& v, ostream& os) { for (vector::const_iterator iter = v.begin(); iter != v.end(); ++iter) { os << *iter << " "; } os << endl; } void swap(int& value_a, int& value_b) { int temp = value_a; value_a = value_b; value_b = temp; } void buble_sort(vector& v, ostream* ofil=0) { vector::iterator ix, iy; for (ix = v.begin(); ix != v.end(); ++ix) { for (iy = ix + 1; iy != v.end(); ++iy) { if (*ix > *iy) { if (ofil) {//need include #include (*ofil) << *ix << " " << *iy << endl; } swap(*ix, *iy); } } } } int main() { vector v = { 0, 1, 0,5,4,3 }; display(v); //swap(v[0], v[1]); //display(v); ofstream fout("test.txt"); buble_sort(v, &fout); display(v); return 0; }