Sort a move to end list
问题 A sequential unique list of numbers (1,2,3,...,n) has been randomized and I need to sort it by moving one item at a time to the end of the list. Which algorithm will provide the least number of moves? Note: [123645] can be sorted with 1 move, [125346] in 2 moves, [654321] will need 5 moves. I'd like an algorithm that can account for these, not one that just gives me n-1 all the time. Best I can think of: for(var x=1; x<=list.length; x++) if indexOf(x+1)<indexOf(x) then move x+1 to end Does