print LinkedList element
This is an to practice traversing a linked list. Given a pointer to the head node of a linked list, print each node's element, one per line. If the head pointer is null (indicating the list is empty), there is nothing to print.
https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list/problem
soultion:
---------------------------------------------------------------------------------------------------------------
void printLinkedList(SinglyLinkedListNode* head) {
SinglyLinkedListNode* temp=head;
while (temp!=nullptr) {
cout<<temp->data<<endl;
temp=temp->next;
}
}
------------------------------------------------------------------------------------
No comments:
Post a Comment