swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

QSort.......


From: Marie-Edith Bissey
Subject: QSort.......
Date: Mon, 29 May 2000 16:24:04 +0100 (WET DST)

Dear all,


Browsing through the archives of this list, I have seen quite a few
questions about QSort, but it seems it is a method quite reluctant to
be used!

So my problem:
I have an array of Value objects, which I would like to rank. In my
program, the Value class is an object wrapper for integers.

The statement: 

[QSort sortObjectsIn: arrayOfDistance];

does not crash the program, but basically does nothing: the elements
in the array are still in the same order.

The statement:

[QSort sortObjectsIn: arrayOfDistance using:M(getMyValue)];

where getMyValue is a function of the Value class returning the
integer value of the object, does something (ie the elements in the
array are in a different order), but does not rank the array in
ascending order.

I have also written a comparison function which I put in the value
class:

-(int)compareValue:value1:value2
        {
        int val1,val2;
        val1=[value1 getMyValue];
        val2=[value2 getMyValue];
        return val1<val2?-1:val1!=val2;
        }

but I am at a loss of where to use it. It is obviously no used by
default, and the statement:

[QSort sortObjectsIn: arrayOfDistance using:M(compareValue)];

results in a run time crash saying:
----------------
      0 [main] coordination 3344 handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
   1426 [main] coordination 3344 stackdump: Dumping stack trace to
coordination.exe.stackdump
-----------------------

So my question(s): what is the correct syntax to use QSort including a
comparison function?
Should the comparison function look like what I have written?
Where should this comparison function be so that QSort will find it?

(Note: I could use a list in place of the array, and it does not
matter if the original array/list is modified).

Thank you very much in advance

Marie-Edith.

__________________________________________________________________

Marie-Edith Bissey                
Universita` del Piemonte Orientale "Amedeo Avogadro"
Facolta` di Science Politiche         email: address@hidden
Corso Borsalino 50                    tel: +39-0131-283749
15 100 Alessandria -- ITALIA          fax: +39-0131-263030




                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]