
import java.util.*;

public class TRAII_25_t3_4_skeleton {

  public static void main(String[] args) {

    // input size
    int N = 1200000;
    if (args.length > 0) N = Integer.parseInt(args[0]);

    // random seed
    int seed = N;
    if (args.length > 1) seed = Integer.parseInt(args[1]);

    // first small list
    Random r = new Random(seed);
    LinkedList<Integer> L = randomLinkedList(20, r);

    // print list
    System.out.println(L.size() < 30 ? L : (L.size() + " element input list"));
    DsaTimer timer = null;
    Integer result = null;

    timer = new DsaTimer("" + L.size());
    result = mostCommon(L);
    timer.stop();
    System.out.println("time: " + timer + ", " + (timer.time() * 1.0 / L.size()) + " ns/elem");
    System.out.println("most common: " + result);

    // a bit larger
    L = randomLinkedList(N, r);

    System.out.println(L.size() < 30 ? L : (L.size() + " element input list"));

    timer = new DsaTimer("" + L.size());
    result = mostCommon(L);
    timer.stop();
    System.out.println("time: " + timer + ", " + (timer.time() * 1.0 / L.size()) + " ns/elem");
    System.out.println("most common: " + result);

    // TODO T4
    // make a program that measures the speed of HashMap and TreeMap for growing input sizes.
    // remember to eliminate possible sources of timing errors (as described at lecture 2).
    // remember to evaluate the results, are they sensible?

  } // main()

  /**
   * Which elements occur most often in collection C?
   * If several elements have the same number of occurences, any of those.
   * @param C Input collection
   * @param <E> element type
   * @return the element that has most occurences.
   */
  public static <E> E mostCommon(Collection<E> C) {
    // TODO
    return null;
  }

  public static LinkedList<Integer> randomLinkedList(int n, int seed) {
    Random r = new Random(seed);
    LinkedList<Integer> V = new LinkedList<>();
    for (int i = 0; i < n; i++) V.add(r.nextInt(n));
    return V;
  }

  public static LinkedList<Integer> randomLinkedList(int n, Random r) {
    LinkedList<Integer> V = new LinkedList<>();
    for (int i = 0; i < n; i++) V.add(r.nextInt(n));
    return V;
  }
} // class
