We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Print the Elements of a Linked List
Print the Elements of a Linked List
Sort by
recency
|
836 Discussions
|
Please Login in order to post a comment
static void printLinkedList(SinglyLinkedListNode head) { if(head==null) return; SinglyLinkedListNode currentNode=head; while(currentNode!=null){ System.out.print(currentNode.data +"\n");\using \n for printing output in diffrentline currentNode=currentNode.next; } return;
}
This is my solution for printing the elements of a singly linked list in C#: `
Traverse the list untill you get null as the next address.
if(head!= null){ while(head!= null){ Console.WriteLine(head.data); head = head.next; } }
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
def printLinkedList(head): cur = head while cur is not None: print(cur.data) cur = cur.next