Find algorithm for updating position field...

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

Inputs:-

  1. An item id.

  2. Items updated position.

Output:-

Must return true if all done else false.

Processing:-

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.

Note:-

  1. Any position should not repeat.

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

//