Day 0 - Problems
What is printed by the following pseudocode? Reminder: in Java, a Stack’s push method pushes an element onto the stack, while the pop method pops an element off the stack and returns it.
Stack s = new Stack();
s.push(8);
System.out.println(s.pop());
s.push(10);
s.push(4);
System.out.println(s.size());
System.out.println(s.pop() - s.pop());What is printed by the following pseudocode? Reminder: in Java, a Queue’s add method enqueues an element, and its remove method dequeues and returns an element.
Queue q = new Queue();
q.add(8);
System.out.println(q.remove());
q.add(10);
q.add(4);
System.out.println(q.size());
System.out.println(q.remove() - q.remove());Implement (in java-like pseudocode) the following method:
/** Reverse the elements of a in-place */
public static void reverse(int[] a) {
// your code here
}Implement (in java-like pseudocode) the following method; you may use extra storage, but the end result must be that s contains the same elements but in reverse order:
/** Reverse the elements of s in-place */
public static void reverse(Stack s) {
// your code here
}The Node class below defines a doubly-linked list node:
public class Node {
int value;
Node next;
Node prev;
}Implement (in java-like pseudocode) the following method:
/** Reverse the order of the doubly linked list with the given head node. */
public static void reverse(Node head) {
// your code here
}