Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package josephus;
- /**
- *
- * @author HavardTollefsen
- */
- public class Queue {
- private Object[] tab;
- private int start;
- private int slutt;
- private int antall;
- public Queue(int str) {
- tab = new Object[str];
- }
- public boolean tom() {
- return antall == 0;
- }
- public boolean full() {
- return antall == tab.length;
- }
- public void leggIQueue(Object e) {
- if (full()) return;
- tab[slutt] = e;
- slutt = (slutt+1)%tab.length;
- antall++;
- }
- public Object nesteIQueue() {
- if(!tom()) {
- Object e = tab[start];
- start = (start+1)%tab.length;
- --antall;
- return e;
- }
- else return null;
- }
- public Object sjekkQueue() {
- if(!tom()) return tab[start];
- else return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement