separate (Tracker.Manipulate_Data.Prioritize)
procedure Sort_El_In_Ms is
    --------------------------------------------------------------------------------
    --|
    --|  NAME:  SORT_EL_IN_MS
    --|
    --|  OVERVIEW:
    --|    This procedure sorts the elements belonging to a given milestone by
    --|    element priority.  If all elements have the same priority, no sorting
    --|    takes place.  Otherwise, sorting is done by deleting the lowest
    --|    priority elements and adding them to the end of the element list.
    --|
    --|  EXCEPTIONS HANDLED:
    --|    others   an error message is printed and execution continues
    --|
    --|  HISTORY:
    --|    written by   Bonnie Burkhardt   March 1985
    --------------------------------------------------------------------------------

    use El_List_Pkg;

    Ele_Ptr : Element_Pointer;
    End_List : Boolean := False;
    Hi_Ms : Ms_Num_Type := 1;
    Lo_Ms : Ms_Num_Type := 1;
    Sorted_El_List : El_List_Pkg.List_Type;
    Succeed : Boolean := False;

begin
    Lo_Ms := Ms_Ptr.Number;
    Hi_Ms := Ms_Ptr.Number;

    -- find the lowest and highest element priority
    Start_Walk (Ms_Ptr.Element_List);

    loop
        Walk (Ms_Ptr.Element_List, Ele_Ptr, End_List);
        exit when End_List;

        if Ele_Ptr.Priority < Lo_Ms then
            Lo_Ms := Ele_Ptr.Priority;
        end if;

        if Ele_Ptr.Priority > Hi_Ms then
            Hi_Ms := Ele_Ptr.Priority;
        end if;
    end loop;

    -- if elements have different priorities, sort them
    if Lo_Ms < Hi_Ms then
        for Priority in Lo_Ms .. Hi_Ms loop

            Start_Walk (Ms_Ptr.Element_List);

            loop
                Walk (Ms_Ptr.Element_List, Ele_Ptr, End_List);
                exit when End_List;

                if Ele_Ptr.Priority = Priority then
                    Add (Sorted_El_List, Ele_Ptr.Desc_Key, Ele_Ptr);
                end if;
            end loop;

        end loop;

        Ms_Ptr.Element_List := Sorted_El_List;
    end if;

exception
    when others =>
        Put_Line ("exception raised in SORT_EL_IN_MS.");
end Sort_El_In_Ms;
