Reordering a list of positional items
c#
Solution
How large are the lists likely to be? `List<T>` is likely to be the easiest representation of the collection, but it means a copy is required every time you insert into or remove from the middle of the list. "Editing" the list basically means a remove/insert.
Iteration is then straightforward.
An alternative might be `LinkedList<T>` - which makes iteration simple and "insert after", "insert before" and "delete" cheap if you hang onto the `LinkedListNode<T>` associated with each of your approvers. But it doesn't make it easy to say "this reviewer should now be at position 3" - you'd have to iterate through to find position 3 first (or 2, anyway). If it's a case of "move this approver after this one" then it's ideal.
Problem
I have a Request object which contains a list of Approvers. An approver has a name and an approval position. - Mathew - Mark - Luke - John Ultimately, a request will move through this chain, starting at Mathew and ended at John. I need to be able to re-order these allowing adds and deletes as outlined below. An approver can be - Added at a certain position - ie. Add Peter at position 3 in which case the new order would be - Mathew - Mark - Peter - Luke - John Delete - ie. Delete Mark in which case the new order is - Mathew - Luke - John Edited - ie you can change John's position to 1 in which case the new order is - John - Mathew - Mark - Luke I have come up with a number of solutions, however none of them is particular elegant. Any help would be much appreciated