Guest User

Untitled

a guest
Jul 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package algoritmer.oving3;
  2.  
  3. public class Kø {
  4. private Object[] tab;
  5. private int start = 0;
  6. private int slutt = 0;
  7. private int antall = 0;
  8.  
  9. public Kø (int str) {
  10. tab = new Object[str];
  11. }
  12.  
  13. public boolean tom() {
  14. return antall == 0;
  15. }
  16.  
  17. public boolean full() {
  18. return antall == tab.length;
  19. }
  20.  
  21. public void leggIKø(Object e) {
  22. if (full()) return;
  23. tab[slutt] = e;
  24. slutt = (slutt+1)%tab.length;
  25. ++antall;
  26. }
  27.  
  28. public Object nesteIKø() {
  29. if (!tom()) {
  30. Object e = tab[start];
  31. start = (start + 1)%tab.length;
  32. --antall;
  33. return e;
  34. }
  35. else return null;
  36. }
  37.  
  38. public Object sjekkKø() {
  39. if (!tom()) return tab[start];
  40. else return null;
  41. }
  42.  
  43. }
Add Comment
Please, Sign In to add comment