Created
September 20, 2018 16:23
-
-
Save thuvh/a7bb2f8982743e4397267ad3190ef04f to your computer and use it in GitHub Desktop.
insertnodeattail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* For your reference: | |
* | |
* SinglyLinkedListNode { | |
* int data; | |
* SinglyLinkedListNode* next; | |
* }; | |
* | |
*/ | |
SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) { | |
SinglyLinkedListNode* tail = new SinglyLinkedListNode(data); | |
if (head == nullptr){ | |
return tail; | |
} else { | |
SinglyLinkedListNode* tmp = head; | |
while(tmp->next != nullptr){ | |
tmp = tmp->next; | |
} | |
tmp->next = tail; | |
} | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment