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.
#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]
#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]