In this part, you will complete the implementation of WeirdList. A WeirdList is
ID: 3598475 • Letter: I
Question
In this part, you will complete the implementation of WeirdList. A WeirdList is sort of like an IntList, except that it has to be implemented without using if, switch, while, for, do, try, ?:. You may not ad any additional methods to WeirdList.
public class WeirdList {
/ The empty sequence of integers. /
// REPLACE LINE BELOW WITH THE RIGHT ANSWER. public static final WeirdList EMPTY = null ;
// A new WeirdList whose head is HEAD and tail is TAIL public WeirdList ( int head , WeirdList t a i l ) { / FILL IN /
}
/ Returns the number of elements in the sequence that starts with THIS. /
public int length () {
return 0; // REPLACE THIS LINE WITH THE RIGHT ANSWER.
}
/ Print the contents of THIS WeirdList on the standard output
(on one line, each followed by a blank).
Does not print an endofline. /
public void print() { / FILL IN / } }
Explanation / Answer
Please find the filled sections with the required code in the program to implement WeirdList .
public class WeirdList {
/ The empty sequence of integers. /
public static final WeirdList EMPTY = new WierdListEmpty(0,null); // The null is replaced in this line.
// A new WeirdList whose head is HEAD and tail is TAIL
public WeirdList ( int head , WeirdList tail)
{
this.head= head;
this.tail=tail; // The code is filled
}
/ Returns the number of elements in the sequence that starts with THIS. /
public int length () {
return this.tail.length() + 1; // The code is replaced
}
/ Print the contents of THIS WeirdList on the standard output
(on one line, each followed by a blank).
Does not print an endofline. /
public void print() {
System.out.print(_head + " " );
_tail.print(); // The code is filled
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.