recursion - How to add a node at front of linked list recursively in java -


i need add node @ front of linked list using recursion.

below add method i'm trying implement. figure out how add @ of linked list :(

    public void add(e element)     {         node<e> newnode = new node<e>(element, null);          if (this.next == null)         {             this.next = newnode;         } else {             next.add(element);         }     } 

to add item front of single-linked list create new node , make point first node of list.

this new node new first node of linked list.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -