[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 8 14:24:42 1998 
Subject:Sorting a list of lists... Part 2! 
From:David FitzGerald 
Volume-ID:980208.01 

Thanks for the help on sorting....
I have managed to get it working for a list of lists that the same
element does not come up twice.

here is a fragment of the code I am using...


it's still in testing, and incomplete - especially the loops.

As far as I can make out the problem occurs in this line:


delete(bigger, templist) -> templist;

When, say [0 1] is assigned to the varibale bigger and [0 1] occours
twice, it gets deleted twice. And that leads to a list shorter than it
ought to be, causing problems with loops. Is it possible to only delete
it once?

Thanks Dave....




define heur_crossing_list(crossing_list) -> heur_list;

    lvars templist;
    lvars maniplist;
    [] -> maniplist;
    lvars item1;
    lvars item2;
    lvars bigger;

    [[0 2] [0 3] [0 1] [0 4]] -> crossing_list;
    crossing_list -> templist;

    ;;; repeat length(crossing_list) times
    ;;;repeat length(templist) times


        if length(templist) = 1 then
        hd(templist) -> bigger;

        else

        hd(templist) -> item1;

        hd(tl(templist)) -> item2;
       
        if addup(item1) > addup(item2) then item1 -> bigger;
        else item2 -> bigger;
        endif;
        endif;

        bigger :: maniplist -> maniplist;



            delete(bigger, templist) -> templist;


    endrepeat;
    maniplist -> templist;
    [] -> maniplist;
    ;;; endrepeat;
    [mn]=>
    maniplist=>
    [tl]=>
    templist=>

enddefine;




define addup(list)-> sum;
    if      list = []
    then    0 -> sum
    else    hd(list) + addup(tl(list)) -> sum
    endif
enddefine;