0

I have a list of elements that have: id, name and priority, those elements are shown in the interface, where 1 is the highest priority.

I can add any element to this list, and I can choose the priority, by default I show the next value according to the last one inserted, but if the user chooses a priority that already is there, I need to update the other ones priority, for example, I have ten elements with priority 1 to 10 and I create a new one and I choose priority 3, the current three must change to 4 and so one, so the lowest priority would be 11 now (it was ten before)

Has anyone done somthing similar?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
zepol
  • 187
  • 5
  • 20
  • 2
    See the javadoc of `PriorityQueue` – janos Jul 21 '17 at 20:35
  • 1
    Look up a [Priority Queue](https://en.wikipedia.org/wiki/Priority_queue) – victor Jul 21 '17 at 20:35
  • Possible duplicate of [Updating Java PriorityQueue when its elements change priority](https://stackoverflow.com/questions/1871253/updating-java-priorityqueue-when-its-elements-change-priority) – MWiesner Jul 21 '17 at 21:41
  • You don't need the priority field at all, or all the mess of adjusting it. You just need the position in the list. If the user chooses 4, insert it at position 4, or rather 3. – user207421 Jul 21 '17 at 22:39

0 Answers0