static void out(stringQueue q) { while(!q.empty()) { String text = q.dequeue(); System.out.println(text+" was removed from the queue"); } }As you know, stringQueue is an abstract class. Why is this method written with an object of an abstract class as a parameter that has no implementation?
|5 |===|15|===|-8|===|3 |===|6 |===|| head Now assume the following node class: class Node { int element; Node next; Node prev; Node (Node n, Node p, int e) { prev=p; next=n; element=e; } }
public class intList { public intList() public boolean empty() public int find(int val) public void append(int val) public int addBefore(int pos, int val) public int addAfter(int pos, int val) public int remove(int pos) public int valAt (int pos) public int last() /** Return the position of the last element **/ public String dump () }(20 Pts.) 3. Write the code for the following methods. Note that they are NOT part of the intList class:
public String dump () { String text; if (head == null) text = new String ("List is Empty"); else { text= new String("head-> "); Node temp; int last; for (temp=head,last=0;temp != null;temp=temp.next,last++) text=text.concat(new String(temp.element + "-> ")); } return text; }Write a recursive method that creates the string holding the values from the list. This is the way dump would use your recursive method:
public String dump () { String text; if (head == null) text = new String ("List is Empty"); else { text= new String("head-> "); text.concat(recursiveDump(head)); } }
public static int fib (int n) { if ((n==1)||(n==2)) return 1; // base case return fib(n-1) + fib(n-2); // note that two separate calls are made } fib(5) {return 5} fib(4) + fib(3) {return 3} {return 2} fib(3) + fib(2) fib(2) + fib(1) {return 2} {return 1} {return 1} {return 1} fib(2) + fib(1) {return 1} {return 1}What will this method return if we send it 6 as an argument, in search of the 6th Fibonacci number? You don't need to show a trace!