π One-stop destination for all your technical interview Preparation π
Itβs like insertion sort.
void insert(vector<int> &v, int temp)
{
if (v.size() == 0 || v[v.size() - 1] <= temp)
{
v.push_back(temp);
return;
}
int val = v[v.size() - 1];
v.pop_back();
insert(v, temp);
v.push_back(val);
}
void sortArr(vector<int> &v)
{
if (v.size() == 1)
return;
int temp = v[v.size() - 1];
v.pop_back();
sortArr(v);
insert(v, temp);
}