CObList SetAt method problem....

D

deneb.dizajn

I'm writing this sorting just to understand how exactly works methods
in CObList. Iteration works fine, but it won't change pointers.

CObList myList;
CPerson* first, second;
POSITION next, position;
int size = myList.GetCount();

for (int i = 0; i < size; i++) {
for (position = myList.GetHeadPosition(); next != NULL;)
{

first = (CPerson*)myList.GetNext(position);
next = position;
second = (CPerson*)myList.GetNext(next);

if (first->get_Number() > second->get_Number())
{
temp = first;
myList.SetAt(position, second);
myList.SetAt(next, temp);
}
}
}

Thanks!
 
I

Ian Collins

I'm writing this sorting just to understand how exactly works methods
in CObList. Iteration works fine, but it won't change pointers.
What's a CObList? Looks like you want a platform specific group.
 
J

John Harrison

I'm writing this sorting just to understand how exactly works methods
in CObList. Iteration works fine, but it won't change pointers.

CObList myList;
CPerson* first, second;

second isn't a pointer, you meant

CPerson *first, *second;
POSITION next, position;
int size = myList.GetCount();

for (int i = 0; i < size; i++) {
for (position = myList.GetHeadPosition(); next != NULL;)
{

first = (CPerson*)myList.GetNext(position);
next = position;
second = (CPerson*)myList.GetNext(next);

if (first->get_Number() > second->get_Number())
{
temp = first;
myList.SetAt(position, second);
myList.SetAt(next, temp);

Don't see why you need temp

myList.SetAt(position, second);
myList.SetAt(next, first);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top