X = 0;
for i = 1 to N do
- for j = i to N do
- for k = j to N do
- X++;
What is its running time in big-Oh notation?
H --> (a) --> (b) --> (c) --> (d) --> (e) --> null.Write a Java method called LastButOne to return a reference to the last but one node (this is node (d) in the figure above). In case the list has only one node, then return H itself. Here is the header for your method:
public Node LastButOne(Node H);
Note: the class Node has a public method called getNode()
that returns a reference to the next node in the list.
pre: (e, c, a, b, d)Draw the binary tree. HINT: looking at the pre-order list, you know where to place node e and node c. But node a has two possible places.
post: (a, b, c, d, e)
class Hello { public static void main(String[] args){ System.out.println("Hello World!"); } }
public Node LastButOne(Node H){ Node Prev = H; H = H.getNext(); if (H == null) { return Prev; }; while (H.getNext() != null){ Prev = H; H = H.getNext(); } }