|
- package gr.auth.ee.dsproject.node;
-
- /**
- * @brief
- * A queue implementation for (x, y) coordinates
- */
- public class Queue2D
- {
- int [][] q;
- //int f;
- int r;
- int size, nItem;
-
- public Queue2D () {
- //f = 0;
- r = 0;
- size = nItem = 0;
- q = null;
- }
-
- public Queue2D (int size) {
- //f = 0;
- r = -1;
- nItem = 0;
- this.size = size;
- q = new int[size][2];
- }
-
- public int size () { return nItem; }
- public boolean isEmpty () { return (nItem == 0) ? true : false; }
- public boolean isFull () { return (nItem >= size) ? true : false; }
-
- public int [] peek () {
- int [] none = {-1, -1};
- if (!isEmpty ()) {
- return q[0]; //return q[f];
- }
- else
- return none;
- }
-
- public int [] insert (int [] it) {
- int [] none = {-1, -1};
-
- if (!isFull ()) {
- ++r;
- q[r][0] = it[0];
- q[r][1] = it[1];
- ++nItem;
- return it;
- }
- else
- return none;
- }
-
- public int [] remove () {
- int [] ret = {-1, -1};
- if (!isEmpty ()) {
- ret[0] = q[0][0]; //ret[0] = q[f][0];
- ret[1] = q[0][1]; //ret[1] = q[f][1];
- for (int i=0 ; i<r ; ++i) {
- q[i][0] = q[i+1][0];
- q[i][1] = q[i+1][1];
- }
- //++f;
- --r;
- --nItem;
- return ret;
- }
- else
- return ret;
- }
- }
|