implementing a sorting feature

I'm using a derivative of the Java language,called APEX from Salesforce. It is similar to the Java language, so I was hoping I might find some help on this forum and get some guidance on the logic I am trying to implement.

I'm trying to re-sort a list when a new record is added or an existing record is updated.

For example, when a record is created, the field is given a sort order number by the user. Assuming we have 10 records, with the sort order numbers going from 1 - 10, I want to re-sort when an existing record is updated or new record is added.

Task Name ----------- Sort Order

Task 1 1

Task 2 2

Task 3 3

Task 4 4

Task 5 5

Task 6 6

Task 7 7

Task 8 8

Task 9 9

Task 10 10

So, if a new Task is added "Task 11" but is given a sort order of 5 then I need to adjust all the above reocrds so that Task 5 has a sort number of 6, Task 6 has a sort number of 7, Task 7 has a sort number of 8, etc. I just need to re-sort the list based on how the sort numbers are changed.

In my code, I'm querying a list to return a list of Tasks that are back logged, these are the only records that apply to be re-sorted. So, I need to loop over that list and re-sort.

List<Project_Management_Task_List__c> lstBacklog = [Select Sort_Order__c From Project_Management_Task_List__c Where Status__c = 'Backlog'];

I was looking into insertion sort, bubble sort and selection sort algorithms, but I couldn't get it to work correctly.

Any help would be greatly appreciated.

Thanks.