Sorting a CList
- From: Anders Eriksson <andis59@xxxxxxxxx>
- Date: Thu, 14 Jun 2007 16:16:41 +0200
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!
.
- Follow-Ups:
- Re: Sorting a CList
- From: Joseph M . Newcomer
- Re: Sorting a CList
- From: MrAsm
- Re: Sorting a CList
- From: MrAsm
- Re: Sorting a CList
- Prev by Date: Re: question about bstr properties
- Next by Date: Re: debug a document double click
- Previous by thread: CFile
- Next by thread: Re: Sorting a CList
- Index(es):
Relevant Pages
|