Sort Two Lists with relationship

后端 未结 1 1156
一向
一向 2021-01-29 12:25

As I can sort two lists or two vectors, ie I sort a list (distances) and according to her order as I ordered another list that keeps me indexes. Thanks.

Pd. I\'m working

1条回答
  •  庸人自扰
    2021-01-29 12:58

    List scores = GetScores();
    List fruit = GetFruit();
    
    List> sortedPairs = scores
      .Zip(fruit, (s, f) => Tuple.Create(s, f))
      .OrderBy(x => x.Item1)
      .ToList();
    
    scores = sortedPairs.Select(x => x.Item1).ToList();
    fruit = sortedPairs.Select(x => x.Item2).ToList();
    

    Now all you have to do is implement Zip, OrderBy, Select, ToList and Tuple.

    0 讨论(0)
提交回复
热议问题