A linked list class uses a Node class with successor reference next and field element to store values. A recursive method to print all list elements can be written as
A)
static void printList(Node list)
{
if (list != null)
{
System.out.println(list.element);
printList(list.next);
}
}
B)
static void printList(Node list)
{
while (list!= null)
{
System.out.println(list.element)
printList(list.next);
list = list.next;
}
}
C)
static void printList(Node list)
{
while (list.next != null)
{
printList(list.next);
System.out.println(list.element)
list ++;
}
}
D)
static void printList(Node list)
{
System.out.println(list.element):
printList(list.next);
}
A)
static void printList(Node list)
{
if (list != null)
{
System.out.println(list.element);
printList(list.next);
}
}
You might also like to view...
In a recursive function, the statement(s) that invoke the function again are called the ______________.
Fill in the blank(s) with the appropriate word(s).
Answer the following statements true (T) or false (F)
1. Recursion is never absolutely required to solve a problem. 2. Recursion can be a powerful tool for solving repetitive problems and is an important topic in upper-level computer science courses. 3. Although SQL is a language, you don't use it to write applications. 4. The columns in a table are assigned SQL data types.
Analyze the following code:
``` public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); } } ``` a. The program has compile errors because the variable radius is not initialized. b. The program has a compile error because a constant PI is defined inside a method. c. The program has no compile errors but will get a runtime error because radius is not initialized. d. The program compiles and runs fine.
As shown in the accompanying figure, the ____ keyword will save existing data when resizing an array to a larger size.
A. Preserve B. Save C. As D. ReDim