Question: We are given a simple linked list (not doubly linked or double ended). The front of the list is referenced by a Node called front
We are given a simple linked list (not doubly linked or double ended). The front of the list is referenced by a Node called front.
4) (10 points) We wish to have a method in our LinkedList class called len( ) that returns the length of the list. Write len ( ). See below for details.
5) (10 points) We wish to have a method in our LinkedList class called penultimate( ) that will print out the second to last Node in the linked list. If the linked list is empty or contains only 1 Node, it should print out Not found, otherwise it should print out the data contained in the Node (assume there is a toString( ) method defined for the Node). Write penultimate( ) See below for details.
public class LinkedList
{
Node front;
// lots of stuff here. Constructors, getters, setters, etc.
public int len( )
{
// you need to put the code in here!!
}
public void penultimate( )
{
// you need to write this code
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
