append
(add to end) method.
append
method. Make sure you detect overflow and throw an exception.
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; }
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.
contains
method assuming the array is maintained in unsorted order?
contains
method assuming the array is maintained in sorted order?
Deque
. Deque
has the following methods:
addFirst, addLast, contains, getFirst, getLast, isEmpty, peekFirst, peekLast, pop, push, removeFirst, removeLast, size
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).