-
Insert a Node at the Tail of a Linked List해커랭크(HackerRank) 2018. 8. 19. 17:22반응형
1. 문제
2. 알고리즘
키워드 - 구현, 링크리스트
3. 코드
123456789101112131415161718192021222324252627/*Insert Node at the end of a linked listhead pointer input could be NULL as well for empty listNode is defined asstruct Node{int data;struct Node *next;}*/Node* Insert(Node *head,int data){// Complete this methodNode* node = new Node();node->data = data;node->next = NULL;if (head == NULL) {head = node;return head;}Node* first = head;while (head->next) head = head->next;head->next = node;return first;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Sparse Arrays (0) 2018.08.19 Print the Elements of a Linked List (0) 2018.08.19 Maximum Element (0) 2018.08.19 Print in Reverse (0) 2018.08.19 Reverse a linked list (0) 2018.08.19