I have a simple list of integers,
original = new List<int>() { 3, 6, 12, 7, 7, 7, 7, 8, 10, 5, 5, 4 };
and a temp list of integers,
temp = new List<int>();
and a list of lists,
listOf = new List<List<int>>();
I want the original list to be divided into many lists, I use the following algorithm to assign the looped values to the list temp
and later push the assigned values to listOf
, after that I clear the list temp
so that I can assign new values.
for (int i = 0; i < orginal.Count; i++) {
if (orginal[i] > orginal[i + 1]) {
for (int i2 = i + 1; i2 < orginal.Count; i2++) {
if (orginal[i2] <= orginal[i2 + 1]) {
listin.Add(orginal[i2]);
} else {
listOf.Add(listin);
listin.Clear();
}
}
}
}
The wanted output would be something like:
listOf[0] = 7 7 7 7 8 10
listOf[1] = 5 5
What do I need to change to achieve this output?