Hallo, hab in der Uni eine Aufgabe in welcher ich eine Klasse Queue schreiben soll. Habe jetzt ein Klasse Queue und QueueException. Nun brauch ich allerdings noch eine main-Methode. Wie schreibe ich die? Kann mir vielleicht jemand helfen?
[/code]
Illuvatar: Verschoben in Allgemeines, 14.01.07, 18:05
Code:
ackage Übung11;
import java.lang.String;
public class Queue {
public static final int CAPACITY = 1000;
private int capacity;
private int[] Q;
private int f = 0;
private int s = 0;
public Queue () {
this(CAPACITY);
}
public Queue (int cap) {
capacity = cap;
Q = new int[capacity];
}
public int size () {
return s;
}
public boolean isEmpty () {
return (s == 0);
}
public void enqueue (int element) throws QueueException {
int r;
if (s >= capacity) {
throw new QueueException("k.A.");
} else {
r = (f + s) % capacity;
Q[r] = element;
s++;
}
}
public int front () throws QueueException {
if (s <= 0) {
throw new QueueException("k.A.");
} else {
return Q[f];
}
}
public int dequeue () throws QueueException {
int element;
if (s <= 0) {
throw new QueueException("k.A.");
} else {
element = Q[f];
f = (f + 1) % capacity;
s--;
return element;
}
}
}
Code:
package Übung11;
public class QueueException extends RuntimeException {
/**
* Queue-Ausnahme mit spezifischem Test(msg)
* @param msg
*/
public QueueException (String msg) { super(msg); }
/**
* Queue-Ausnahme
*/
public QueueException() {};
}
Illuvatar: Verschoben in Allgemeines, 14.01.07, 18:05