Function to create Linked List or tree nodes on each level