A java PacMan game application for A.U.TH (data structures class)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB

  1. package gr.auth.ee.dsproject.node;
  2. /**
  3. * @brief
  4. * A queue implementation for (x, y) coordinates
  5. */
  6. public class Queue2D
  7. {
  8. int [][] q;
  9. //int f;
  10. int r;
  11. int size, nItem;
  12. public Queue2D () {
  13. //f = 0;
  14. r = 0;
  15. size = nItem = 0;
  16. q = null;
  17. }
  18. public Queue2D (int size) {
  19. //f = 0;
  20. r = -1;
  21. nItem = 0;
  22. this.size = size;
  23. q = new int[size][2];
  24. }
  25. public int size () { return nItem; }
  26. public boolean isEmpty () { return (nItem == 0) ? true : false; }
  27. public boolean isFull () { return (nItem >= size) ? true : false; }
  28. public int [] peek () {
  29. int [] none = {-1, -1};
  30. if (!isEmpty ()) {
  31. return q[0]; //return q[f];
  32. }
  33. else
  34. return none;
  35. }
  36. public int [] insert (int [] it) {
  37. int [] none = {-1, -1};
  38. if (!isFull ()) {
  39. ++r;
  40. q[r][0] = it[0];
  41. q[r][1] = it[1];
  42. ++nItem;
  43. return it;
  44. }
  45. else
  46. return none;
  47. }
  48. public int [] remove () {
  49. int [] ret = {-1, -1};
  50. if (!isEmpty ()) {
  51. ret[0] = q[0][0]; //ret[0] = q[f][0];
  52. ret[1] = q[0][1]; //ret[1] = q[f][1];
  53. for (int i=0 ; i<r ; ++i) {
  54. q[i][0] = q[i+1][0];
  55. q[i][1] = q[i+1][1];
  56. }
  57. //++f;
  58. --r;
  59. --nItem;
  60. return ret;
  61. }
  62. else
  63. return ret;
  64. }
  65. }