# Help with linked list in c++

**URL:** https://forum.kirupa.com/t/help-with-linked-list-in-c/239502
**Category:** Uncategorized
**Created:** [September 22, 2007, 4:05pm UTC](https://forum.kirupa.com/t/help-with-linked-list-in-c/239502 "2007-09-22T16:05:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![wo1olf](https://avatars.discourse-cdn.com/v4/letter/w/278dde/32.png) [@wo1olf](https://forum.kirupa.com/u/wo1olf)
#### Post date: [September 22, 2007, 4:05pm UTC](https://forum.kirupa.com/t/help-with-linked-list-in-c/239502/1 "2007-09-22T16:05:41Z")

</div>

How can i do to run a loop in a linked list. I know the stl has already one but i can’t use it, because at school they want us to first be familiar with linked list.

```auto
 
#definition of node of the list
[LEFT]class listNode
{ 
  public: 
    listNode* getNext() ; 
    //return the pointer to the next item
    void changeNext(listNode*) ; 
   //change the pointer pointing to the next node
   string getNode_content();
  //return the value of the attribute nodeContent;
 
  private : 
    string nodeContent;
    //informations hold by the node
    listNode* nextNode;
    //pointer to the next node[/LEFT]
}; 
 
#definition of the list
[LEFT]class myList
{ 
  public: 
     myList();
     //constructor
     void addNode(string n);
     //add a new node to the list;
 private : 
     int nbNodes;
     //hold the number of node in the list
     listNode* headList; 
     //pointer to the first node of the list
     listNode* currentPos ;
    //pointer to the current node i.e the last inserted node in the list[/LEFT]
} 

```

[SIZE=2][SIZE=2]  
every thing works, except that i can find a way to run a loop trough the whole list  
here is my attempt

[/SIZE][/SIZE]

```auto
 
#loop on the lsit and show each node content
for(int i = 0; i < nbNodes; i++ )
{
   listNode* tmp = headList-> getNext() ;
   cout <<tmp->getNode_content() <<endl;
}

```

[SIZE=2][SIZE=2][SIZE=2][/SIZE][/SIZE]  
What is not working ?

[/SIZE]
