I have a "pointer" which keeps incrementing and I need to return the "head" of the pointer finally. I am in a dilemma to use either "pointer[0]" or have another variable called "head" and initialize it and return at the end. The former I feel makes the code looks soiled and later costs little memory. Any clean suggestion?
+1
A:
You will always need two variables:
Foo *head = getSomeList();
Foo *tail = head;
while (tail->isValid())
++tail;
// You have head and tail here
You cannot really implement it much differently because tail[0] != head
(unless the list is empty).
Showing the code and telling us what exactly you try to achieve might lead to better answers.
dark_charlie
2010-09-01 13:46:27