Thread: Pointers
View Single Post
Old 03-02-2003, 11:18 AM   #13 (permalink)
arkadius
Registered User
 
Join Date: Mar 2003
Posts: 3
arkadius is on a distinguished road
Ok... yes, the head is the first in the list.

So once I have set the head to the adress of the SL.head, and now I need to traverse the list and actually copy the nodes

Code:
while(pCur->next != NULL)
   {
   pCur = pCur->next; // ok, so this traverses the list
   // but it still references the address of the original node (SL)
   // so calling any function, that mods the list, at this point
   // would affect the SL list, right? So what's next? a new pointer?
   }
So I need something that keeps track of the last node, traverses the SL list, and something that creates the new nodes

Code:
Node *pPrev;
Node *pCur;
Node *pSL;

head = SL.head;
pPrev = head;
pSL = SL.head->next;

while(pSL != NULL)
{
  pCur = new Node;
  pCur->data = pSL->data; 
  pPrev->next = pCur;
  pSL = pSL->next;
  pPrev = pCur;
}
This makes somewhat of a sense to me to, I guess am I waaay of the target? And thank's again
arkadius is offline   Reply With Quote