Sorting a CList

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

I need to sort a CList (No, it not possible to use STL)

I have this code but it there is something wrong with the pointers..
CList<CLaserObject*,CLaserObject*> m_listObjects;

CArray<CLaserObject*,CLaserObject*> vector;
POSITION pos = m_listObjects.GetHeadPosition();
int i=0;
while(pos != NULL)
{
vector.Add(m_listObjects.GetNext(pos));
}
// sort array
qsort(vector.GetData(),vector.GetSize(),sizeof(CLaserObject*),cmpLaserObject);
// empty list and fill it with the sorted data
m_listObjects.RemoveAll();
int n=vector.GetCount();
for(i=0;i<n;i++)
{
m_listObjects.AddTail(vector[i]);
}

int CSCMLaserDoc::cmpLaserObject(const void * v1, const void * v2)
{
CLaserObject *data1 = (CLaserObject *)v1;
CLaserObject *data2 = (CLaserObject *)v2;

}


When I check in the debugger the vector is Ok!
My problem is that when I reach cmpLaserObject the data1 and data2 pointers
doesn't point to the vector

What am I doing wrong?

// Anders
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
.



Relevant Pages

  • Re: Writing a program to sort numbers - HELP!
    ... You may not have a choice but strtol is preferred to atoi and fgets is ... Then we using a sort function to sort the ... >int main ... probably meant *u and *v to dereference the pointers you received from ...
    (comp.lang.c.moderated)
  • Re: Using a link list over an array.
    ... compile (p->data is a void *) so you have not shown us some key ... You can't use it to sort a list of ints where the int is ... You can use it to sort a list of pointers to any type. ...
    (comp.lang.c)
  • Re: resize JTable
    ... >able to easily sort the data, from a user point of view. ... public static final int DESCENDING = -1; ... private Comparator comparator; ... * @param model OrderedTableModel to be kept deduped/sorted. ...
    (comp.lang.java.programmer)
  • Re: A taxonomy of types
    ... I am describing how to represent the representation (and, ... if the system follows static typing rules (such as in a compiler), ... so, the hardware sees pointers and pointer arithmetic, but the compiler ... "Besides the char types, up to three sizes of integer, declared short int, ...
    (comp.lang.misc)
  • C Sharp sorting considered superior to C by an order of magnitude
    ... following sort algorithms and the following points. ... its own comparision for the types bool, byte, short, int, long, ... single, double and string. ... private CheckBox CHKdeterminism; ...
    (comp.programming)