Implementing list using linked list Implementing list using

Implementing list using linked list

Implementing list using linked list size java.lang.Integer size() Determine the size of this list. Returns: the number of elements in this list

Solution

Below is the size() method for LinkedList

public class LinkedList
{ //Start of LinkedList class
private Node first;
public LinkedList()
{
first = null;
}

public Integer size()
{
int s = 0;
Node current = first;
while(current!=null)
{
s++;
current = current.next;
}
  
return s;
}

}

Implementing list using linked list Implementing list using linked list size java.lang.Integer size() Determine the size of this list. Returns: the number of el

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site