Problem
I have several groups that define character relationships ... for example:
[ABC] [ADE] [XYZ]
What these groups mean is that (for the first group) the characters A, B, and C are connected to each other. (Second group) Symbols A, D, E are connected with each other .. etc.
Given all this data, I will need to put all the unique characters in a one-dimensional array in which characters that are somehow connected to each other will be located closer to each other. In the above example, the result should look something like this:
[BCADEXYZ]
or
[XYZDEABC]
In this resulting array, since the symbol A has several relations (namely, with B and C in one group and with D and E in another), it is now located between these symbols, somewhat preserving the connection.
Please note that order is not important. As a result, XYZ can be placed first or last, as these characters are not associated with any other characters. However, the proximity of related characters is important.
I need help in
I need help defining an algorithm that takes a group of character relationships and then outputs a 1-dimensional array using the logic above. I draw my hair out how to do this, since with real data the number of characters in a relationship group can vary, the number of relationship groups is also unlimited, and a symbol can have a relationship with any other symbol.
Further example
To illustrate the trick of my dilemma again, IF you add another relationship group to the example above. Let them talk:
[CZ]
The result should now look something like this:
[XYZCBADE]
Please note that the characters Z and C are now closer to each other, as their relationship is reinforced by additional data. All previous relationships are still maintained as a result.