I have the following task:
Give a recursive algorithm for filling an array like this: one 1, two 2, tree 3, four 4, ... ,n n.
For example, with n = 4 the array is supposed to look like:
{ 1, 2, 2, 3, 3, 3, 4, 4, 4, 4 }
My attempt is
Function filling(T, k, n)
if (n = 0) do return 1
else if (0 <= k) do filling (T, n - k + 1, n);
else filling(T, k, n - 1);
fi
fi
with filling(T, k, n)
k: block start case of number n,n: number,T: array