[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Feb 7 16:13:58 1998 
Subject:Re: Sorting a list of lists. 
From:Aaron Sloman See text for reply address 
Volume-ID:980207.02 

David FitzGerald <D.P.Fitzgerald-CSAI97@cs.bham.ac.uk> writes:

> Date: Sat, 07 Feb 1998 15:01:38 +0000
>
> I have been trying to make a procudure to sort a list of lists into
> ascending numberical value. For example, if the list of lists is [[0 1]
> [1 1] [0 3] [4 0]] I would like the outcome to be [[4 0] [0 3] [1 1] [0
> 1]] or [[0 1] [1 1] [0 3] [4 0]] - it doesn't matter.

But your first version is definitely NOT in ascending numerical
value.

If you think you have an algorithm that works, check it out by hand
on some simple examples using pencil and paper to find out whether
it really works. That will often reveal serious design bugs.

> The procedure I have written below doesn't actaully run, but I thoght it
> might let you know how I am attempting to do this.

A few problems you have to fix.

1.  "big" is used as a local variable, but you forgot to declare
it. You should have received a warning message telling you about
every undeclared variable. Such messages need attention.

2. You have a local variable which you use *before* you have given
it a value. That's asking for trouble, as uninitialised lvars have
undefined values and in DEC ALPHA Poplog the value can be any
arbitrary junk that happens to be in a registor. Always initialise
lvars variables.

The problem in this case is your use of "<>" with an undefined
second argument.

3. After you fix that you will have more problems. You can trace
individual procedures (e.g. more) to find out what's going on.
See TEACH TRACE (HELP TRACE gives more information).

4. You use delete, which produces a result, but you don't do
anything with the result. See HELP DELETE

> Unfourtantly it won't run. I'm worried that it may be failing when it
> gets to the last element in a list and attempts to compare it, the head,
> with the head of the nonexistant tail.

Well if you are worried you should put in a test, and if necessary
stop. See HELP QUITLOOP, HELP RETURN

> Am I going about this the right way? A friend reccomended I used the
> syssort command, but it seems quite complicated.

Your friend is right. Look at HELP SYSSORT

What about sorting algorithms studied in your computer science
course?

Aaron
===
-- 
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman at cs.bham.ac . uk
Phone: +44-121-414-4775 (Sec 3711)       Fax:   +44-121-414-4281