开发者

Storing Array elements in an order specified by the user

开发者 https://www.devze.com 2023-04-08 16:03 出处:网络
I\'d like users of my application to be able to rearrange a number of elements in an array into an order of their choice, while maintaining the original array structure. What\'s the best representatio

I'd like users of my application to be able to rearrange a number of elements in an array into an order of their choice, while maintaining the original array structure. What's the best representation of this data? I've considered using decimals (e.g when moving element 4 between element 2 and开发者_StackOverflow社区 3, it gets a value of 2.5) however it seems like this would quickly get complex when working with many values, and may have an unnecessary overhead. Is there a simpler solution to this problem that I've overlooked?


How are they doing the reordering? If it is some kind of drag-and-drop or button to swap two elements or to move one element up or down, the most logical way is to simply swap those two elements in the array.

0

精彩评论

暂无评论...
验证码 换一张
取 消