I have an unsorted list of ints:
1 3 1 2 4 3 2 1
I need to sort it, and in front of each group of equal numbers, insert 0:
0 1 1 1 0 2 2 0 3 3 0 4
Is there a way to get from the first list to the second list only one LINQ statement? I'm stuck in
from num in numbers orderby num select num
followed by a foreach loop that manually creates the final output based on these results. I would like to completely eliminate the second cycle, if possible.
source share