Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package josephus;
  2.  
  3. /**
  4. *
  5. * @author HavardTollefsen
  6. */
  7. public class Queue {
  8. private Object[] tab;
  9. private int start;
  10. private int slutt;
  11. private int antall;
  12.  
  13. public Queue(int str) {
  14. tab = new Object[str];
  15. }
  16.  
  17. public boolean tom() {
  18. return antall == 0;
  19. }
  20.  
  21. public boolean full() {
  22. return antall == tab.length;
  23. }
  24.  
  25. public void leggIQueue(Object e) {
  26. if (full()) return;
  27. tab[slutt] = e;
  28. slutt = (slutt+1)%tab.length;
  29. antall++;
  30. }
  31.  
  32. public Object nesteIQueue() {
  33. if(!tom()) {
  34. Object e = tab[start];
  35. start = (start+1)%tab.length;
  36. --antall;
  37. return e;
  38. }
  39. else return null;
  40. }
  41.  
  42. public Object sjekkQueue() {
  43. if(!tom()) return tab[start];
  44. else return null;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement