해커랭크(HackerRank)

Print the Elements of a Linked List

cepiloth 2018. 8. 19. 17:23
반응형


1. 문제


2. 알고리즘

키워드 - 구현, 출력


3. 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
  Print elements of a linked list on console 
  head pointer input could be NULL as well for empty list
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
void Print(Node *head)
{
    if(!head)
        return ;
  // This is a "method-only" submission. 
  // You only need to complete this method. 
    if(head->data)
        cout << head->data << endl;
    
    Print(head->next);
}
cs

반응형