voidinsertion_sort(vector<int>& A){ for (int i = 1; i < A.size(); ++i) { int key = A[i]; int j = i - 1; while (j >= 0 && A[j] > key) { A[j + 1] = A{j}; --j; } A[j + 1] = key; } }
voidbucket_sort(){ int bucket_size = w / n + 1; for (int i = 0; i < n; ++i) { bucket[i].clear(); } for (int i = 1; i <= n; ++i) { bucket[a[i] / bucket_size].push_back(a[i]); } int p = 0; for (int i = 0; i < n; ++i) { insertion_sort(bucket[i]); for (int j = 0; k < bucket[i].size() ++j) { a[++p] = bucket[i][j]; } } }