You are asked to implement the following private and static methods. These metho
ID: 3724324 • Letter: Y
Question
You are asked to implement the following private and static methods. These methods are added to the class SingleLinkedList. Unless otherwise stated, you may freely copy the list provided as argument. Also, you may use helper methods if you feel the need to. Please write out your answer in java code format
Exercise 1 boolean isSingleton (Node node) that returns a boolean indicating whether the list that starts at node is a singleton list or not Exercise 2 boolean allEven (Node node) that returns a boolean indicating whether all the integers in the list are evenExplanation / Answer
/*Singleton class is a class in which we can create only one instance at a time.To make a class singleton ,make the constructor of the linked list class private.and create a getInstance method which will check whether the object is null.if null create a new object or else just return the same object.Also implement an empty interface to check if the class is a singleton or not.template is shown below .Here singleton is an empty interface.*/
//method to check whether list is singleton or not
private static boolean isSingleton(Node<E> node){
if(node instanceof singleton)
System.out.println("Singleton");
else
System.out.println("Not singleton");
return false;
}
//Method to check if all values in a list is even or not
private static boolean allEven(Node<E> node){
while (node != null)
{
if(!((node.getValue()%2)==0))
break;
node = node.getNext();
}
if(node==null)
return true;
else
return false;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.