Algorithm: optimal way to rearrange a list from one order to another?

后端 未结 4 1026
旧巷少年郎
旧巷少年郎 2020-12-30 13:30

EDIT: I\'m not sure that my original question is clear enough. I need an algorithm that will compute the minimal sequence of moves to rearrange an array from one ord

4条回答
  •  不知归路
    2020-12-30 14:10

    My first thought is you should use Selection sort instead of the built-in sort method, since it makes the lowest ammount of swaps needed. That way you can just move the DOM element around when moving the id in the list.

提交回复
热议问题