Traverse Linked List in C++

Prev Tutorial Next Tutorial

Traverse Linked List in C++

When we want to see the information stored inside the linked list. We create node*temp. Transfer the address of *head to *temp. So *temp is also pointed at the front of the linked list. Linked list has 3 nodes. We can get the data from first node using temp->data . To get data from second node, we shift *temp to the second node. Now we can get the data from second node.

traverse linked list in c++


while( temp!=NULL )
 cout<< temp->>data<<" ";  // show the data in the linked list
 temp = temp->next;  // tranfer the address of 'temp->next' to 'temp'

This process will run until the linked list's next is NULL.

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain,, @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: WhatsApp no. 8882538826

Yahoo Advertisements