help with linked list in c++
#definition of node of the list
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
};
#definition of the list
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
}
every thing works, except that i can find a way to run a loop trough the whole list
here is my attempt
#loop on the lsit and show each node content
for(int i = 0; i < nbNodes; i++ )
{
listNode* tmp = headList-> getNext() ;
cout <
What is not working ?
for(int i = 0; i < nbNodes; i++ )
{
listNode* tmp = headList-> getNext() ;
cout <
What is not working ?
Usually, we iterate the Linked List checking the next pointer value whether its NULL or not.
So, my code would be,
listNode* tmp=headList;
while(tmp->getNext() != null)
{
cout<
}
Hope that helps :)
#If you have any other info about this subject , Please add it free.# |

