CISC 3130
Data Structures
Sample Questions


  1. Given a container class with a fixed-capacity underlying array, and an append (add to end) method.

  2. What is wrong with the following checkCapacity code for a resizeable int-based container?
    void checkCapacity() {
    	if (size < capacity) return;
    	int [] t = new int[capacity+1];
    		
    	for (int i = 0; i < size; i++)
    		t[i] = arr[i];
    	arr = t;
    }
    		

  3. Given an interface named Container, two implementation classes, ContainerImp1 and ContainerImp2, and an interface-specific app, ContainerApp that have all been coded already, code the two implementation container apps using dependency injection.

  4. Given a Set container with an underlying array container,

  5. Write a demo program that creates, populates (100 elements), print, then empties a stack implemented using a JCF Deque. Deque has the following methods: addFirst, addLast, contains, getFirst, getLast, isEmpty, peekFirst, peekLast, pop, push, removeFirst, removeLast, size

  6. Assuming the existence of a class, Stack, (with the usual behavior of a stack) write a method (not of the Stack class), clear(Stack stack), that accepts a stack and clears it (i.e. removes all its elements).

  7. Explain the statement: in Java, methods that are not in an interface but are in a class implementing that interface should, in general, be declared private, are considered part of the implementation, and calling them from an application violates the principle of 'programming to the inteface'.