Traverse Linked List in C++

Advertisements

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++

Syntax

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 Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements