How to start to see the list first?

There is a structure of the bidirectional list.

typedef struct DNode
{
 DNode *next;
 DNode *pnext;
 int value;
} DNode;


Is the class of DList, which has this structure.

class DList
{
 DNode *head = new DNode();
}


But here's the problem, when call the function the first time everything goes well. But if you run it a second time, then the pointer is the place where to stop the cycle. How to make so that when you call different functions, the pointer was shown again to the first node of the list?

int DList::ListNodeNumber() {
 // Determine number of elements in the list

 int counter = 0; // Description and initialization of the counter nodes

 // Check pointer for NULL
 while (head) {
 head = head->next;
counter++;
}

 return counter;
}
June 10th 19 at 16:15
1 answer
June 10th 19 at 16:17
Solution
int DList::ListNodeNumber() {
 int counter = 0;
 DNode *t = head;
 while (t) {
 t = t->next;
counter++;
}
 return counter;
}
Thank you, everything works as it should - nikita.Stracke commented on June 10th 19 at 16:20
then check the solution to the answer. - lourdes_Bins50 commented on June 10th 19 at 16:23

Find more questions by tags C++