123456789101112131415161718192021222324252627282930 |
- class Hylle<T> implements GenHylle<T> {
- private int storrelse;
- private T[] arr;
-
- Hylle(int storrelse) {
- this.storrelse = storrelse;
- this.arr = (T[])(new Object[storrelse]);
- }
-
- public int hentStorrelse() {
- return storrelse;
- }
-
- public void settInn(int plass, T ting) throws Exception {
- if (arr[plass] == null)
- arr[plass] = ting;
- else
- throw new Exception("Plass "+plass+" er ikke ledig.");
- }
-
- public boolean erLedig(int plass) throws Exception {
- return arr[plass] == null;
- }
-
- public T hent(int plass) {
- T ting = arr[plass];
- arr[plass] = null;
- return ting;
- }
- }
|