What is the best way to do - Given a string A, and collection of strings C, order the strings in the collection in the non decreasing order of the position of A in the strings.
For instance,
A= abc
C= [deabc, abc, dabc, dad]
Sorted C= [abc, dabc, deabc]
My idea is to iterate over the collection and put it in a HashMap/Dictionary with the position of A in C[i] as index. And then constructing the sorted collection from HashMap. This is not a homework problem. Just wanted to know the efficient way/algorithm of doing this. Any pointers will be helpful.
var results = yourList.OrderBy(str=>str.IndexOf("abc"))C = [abc, dabc, dabd]?