Repository navigation
Expand file tree
/
Copy pathQueueOfArray.java
More file actions
86 lines (75 loc) · 1.72 KB
/
Copy pathQueueOfArray.java
File metadata and controls
86 lines (75 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class QueueOfArray {
int maxSize; // Maximum Capacity for the queue
String[][] queArray; // The array that holds the items
int front;
int rear;
int nItems;
int width;
// constructor
public QueueOfArray(int height, int width) {
maxSize = height; // set array size
this.width = width;
queArray = new String[maxSize][width]; // create array
front = 0;
rear = -1;
nItems = 0; // no items yet
} // end of constructor
public void enqueue(String[] i) {
// if (rear == maxSize - 1)
// rear = -1;
queArray[nItems] = i; // increment rear, insert item
nItems++;
}
public String[] dequeue() {
String[] result = queArray[0]; // get value
for (int i = 0; i < nItems - 1; i++) {
queArray[i] = queArray[i + 1];
}
// front++; // increment front
// if (front == maxSize) // deal with wraparound
// front = 0;
nItems--;
return result;
}
@SuppressWarnings("unused")
public void remove(int index) {
if (index == 0) {
dequeue();
} else {
String[][] temp = new String[maxSize - 1][width];
int counter = 0;
for (int i = 0; i < maxSize; i++) {
if (i == index) {
String[] temp2 = dequeue();
} else {
temp[counter] = dequeue();
counter++;
}
}
for (int j = 0; j < maxSize - 1; j++) {
enqueue(temp[j]);
}
}
}
public String[] peek() {
return queArray[0];
}
public boolean isEmpty() {
return (nItems == 0);
}
public boolean isFull() {
return (nItems == maxSize);
}
public int size() {
return nItems;
}
public String get(int row, int coloumn) {
return queArray[row][coloumn];
}
public String[] getArray(int index) {
return queArray[index];
}
public void modify(int row, int coloumn, String val) {
queArray[row][coloumn] = val;
}
}