First, I don’t know if the title is appropriate for what I want to do. Maybe it has another name.
So let’s say I have a list ordered as follows:
dog1
dog2
dog3
cat1
cat2
cat3
hen1
hen2
hen3
and what I want is
dog1
cat1
hen1
dog2
cat2
hen2
dog3
cat3
hen3
Is there a standard algorithm for this, or is it user’s choice? What I was thinking was numbering them first and then bringing out the index in front.
11dog1
22dog2
33dog3
14cat1
25cat2
36cat3
17hen1
28hen2
39hen3
From there I would sort them and then remove the index. Is there a more elegant way?
My idea is that you separate each line in individual arrays.
Then create another array where to store the result and do something like this: