I have a List of strings that I want to bring in a certain order. Let's say the list contains a random amount of the strings "A", "B" and "C". And I have another List of strings containing the sort order.
For Example: For input:
"A"
"A"
"C"
"B"
"B"
"C"
with sort order List:
- "A"
- "B"
- "C"
I want to order this List that the output looks like this:
- "A"
- "B"
- "C"
- "A"
- "B"
- "C"
another example:
For Input:
- "A"
- "A"
- "C"
- "B"
- "C"
with sort order List:
- "A"
- "C"
- "B"
output should look like this:
- "A"
- "C"
- "B"
- "A"
- "C"
Note: I chose A, B and C only for the sake of simplicity so in my real application I won't be able to make use of any alphabetical order.
Is there any way to achieve the desired result? I wrapped my head around this for days and didn't come up with a solution. I tried to implement IComparer but I was struggling with the conditions for compare - method.