Print Linked List elements



You are given the pointer to the head node of a linked list. You have to print all of its elements in order in a single line.



Example:

Input:

N=2

LinkedList={1 , 2}

Output:

1 2


N=5

LinkedList={4,6,2,4,7}

Output:

4 6 2 4 7


c++  implementation :

void display(Node *head)
{
   while(head!=NULL)
   {
       cout<<head->data<<" ";
       head=head->next;
   }
}

time complexity:0(n) where n is the no.of elements in linked list

No comments

darkmode