Question: Add element to the end of the SinglyLinkedList using recursion. Signature: void addLastRecursive (Node yourVariableName) this is addend method in java * public void addLast(E
Add element to the end of the SinglyLinkedList using recursion. Signature: void addLastRecursive (Node
this is addend method in java
* public void addLast(E e) { // adds element e to the end of the list Node
and this is the ALGORITHM
addLast(e): newest = Node(e) // create new node instance and store reference to element e newest.next = null // set new nodes next to reference the null object tail.next = newest // Make old tail node point to new node tail = newest // set variable tail to reference the new node size = size +1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
