#include #include #include using namespace std; void Insert(vector & ary, int data); int main() { vector ary; vector cmp; int data; srand(static_cast (time(nullptr))); for(int i=0; i < 10; i++) { data = rand() % 1000; Insert(ary, data); cmp.push_back(data); } sort(begin(cmp), end(cmp)); if(cmp != ary) { cout << "Error, the array is wrong" << endl; } for(auto x: ary) { cout << x << " "; } cout << endl; return 0; } void Insert(vector & ary, int data){ size_t loc; ary.push_back(data); loc = static_cast(ary.size()) - 1; while (loc > 0 and ary[loc-1] > data) { ary[loc] = ary[loc-1]; loc --; } ary[loc] = data; return; }