swarm-modeling
[Top][All Lists]
Advanced

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

[Question] using Map, setCompareFunction, ordering lists


From: Norberto Eiji Nawa
Subject: [Question] using Map, setCompareFunction, ordering lists
Date: Tue, 15 Jun 1999 20:31:22 +0900

Hello everybody,

I am trying to construct an ordered list (sellList), using my own
comparison function (comparePrice), as below:

(...)
sellList = [Map createBegin: [self getZone]];
// Set the comparison function
[sellList setCompareFunction: comparePrice];
sellList = [sellList createEnd];
(...)

where comparePrice is defined as:

int comparePrice(id c1, id c2) {

  int out1, out2;
  
  out1 = [c1 getPrice];
  out2 = [c2 getPrice];
  printf("out1:%d out2:%d\n", out1, out2);

  if (out1 == out2)
    return 0;

  if (out1 < out2)
    return -1;

  return 1;
}

The problem is that I am getting a segmentation fault in [c1
getPrice], when sellList contains already one element.

I feel I am missing something here...

[newbie question]: do I have to care about having c1 and c2 pointing
to the right objects? Or c1/c2 is the object already in the list and
c1/c2 is the new object to be inserted? Or am I really missing the
point here?

Thanks a lot for your patience,

Eiji


                  ==================================
   Swarm-Modelling is for discussion of Simulation and Modelling techniques
   esp. using 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]