Find algorithm for updating position field...

I need an algorithm that updates position of one or more fields.


  1. An item id.

  2. Items updated position.


Must return true if all done else false.


I have a list of items.

When i re-order the position of any item the positions of all those items must update if require else only that particular item position updates.


  1. Any position should not repeat.

  2. Maximum position must be equal to total number of items.