Data:
List<List<int>> startList - list where is populated lists of integers, inner list has mostly 2 elements like: {[1,2], [2,3],[3,1]};
Task: Need to write algorithm which will join innerLists, where last of list element equals first element of list.
Example:
List<List<int>> startList = {[1,2],
[2,3],
[4,7],
[7,4],
[3,1],
[6,2],
[3,2],}
and result should be: {[1,2,3,1],[1,2,3,2],[4,7,4],[6,2]}
As for me, I can find out how to do this using several dimensions loops like:
while(true)
{
...
for (List<String> list : startList)
{
...
for (List<String> list : startList)
{
...
}
}
}
But is very bad solution, because when it is lot data (like 5000 inerLists) it will work for hours. So maybe someone can suggest better solution?
List<int>? ...You can't use primitives withList