rotation of elements within a list
I have a List which contains 5 element [a,b,c, d, e]. Based on user selection I would like to change the display order and would like to know if there are functions which can give me a newly ordered list.
e.g. If user selects d, e to move 1 position up, the resultant order will be [a,b,d,e,c]
e.g. If user selects b, e to move 1 position up, the resultant order will be [b,a开发者_高级运维,c,e,d]
e.g. If user selects b, d, e to move 1 position up, the resultant order will be [b,a,d,e,c]
Is there an out of the box function which can do this?
In both cases you're swapping adjacent elements. Basically,x=a[i]; a[i]=a[j]; a[j] = x;
I think you are looking for Circular Linked List
You'd put the user selection at index 1 and traverse remaining list.
Looks like a simple requirement for which neither JDK-collections, common-collections or google collections have an answer.
I would suggest writing one :)
精彩评论