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 yourVariableName)

this is addend method in java

* public void addLast(E e) { // adds element e to the end of the list Node newest = new Node<>(e, null); // node will eventually be the tail if (isEmpty()) head = newest; // special case: previously empty list else tail.setNext(newest); // new node after existing tail tail = newest; // new node becomes the tail size++; ----------------------------------------------------------------------------

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!