Good day! There is a problem for which it is necessary to sort a two-dimensional array in a certain order.
Suppose there is an array of string arrays:
{root, dir1, dir2, dir3, file1}: {root, dir2, file} {root, dir3, file} {root, dir1, dir3,file} {root, dir3, dir1, file} {root, dir1, dir2} {root, file}
You need to get the following:
{root, dir1, dir2, dir3, file1} {root, dir1, dir2} <--- 2 {root, dir1, dir3,file} <--- 3 {root, dir3, dir1, file} <--- 1 {root, dir3, file} {root, dir2, file} {root, file}
That is, (I will try to explain in simple language, do not kick the explanation for much) with the first line we print the longest array, then the arrays that have common data with the first array (up to root
value) are output. When these arrays end we look back the longest of the remaining (1) and in the same vein we derive as at the beginning and so on until the end .. Please also pay attention to line (2), its length is less than line (3), but it is in the right place, because dir2
is common, and in line (3) common is dir1
. In general, something like that ... Thank you in advance for any help!