Skip to content

Instantly share code, notes, and snippets.

@igaozp
Created June 19, 2016 08:55
Show Gist options
  • Save igaozp/e12c3267015622b33c6ce00289fb463d to your computer and use it in GitHub Desktop.
Save igaozp/e12c3267015622b33c6ce00289fb463d to your computer and use it in GitHub Desktop.
/*
  Print elements of a linked list on console 
  head pointer input could be NULL as well for empty list
  Node is defined as 
  class Node {
     int data;
     Node next;
  }
*/

// This is a "method-only" submission. 
// You only need to complete this method. 
    
void Print(Node head) {
    if(head == null || head.next == null){
        return;
    }else{
        Node temp = head;
        while(temp != null){
            System.out.println(temp.data);
            temp = temp.next;
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment