-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringQueue.java
More file actions
61 lines (47 loc) · 1.13 KB
/
Copy pathStringQueue.java
File metadata and controls
61 lines (47 loc) · 1.13 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
public class StringQueue {
String[] q;
int length;
StringQueue (int size){
q = new String[size];
length = 0;
}
public void enqueue(String s){
//2 3 5
if(length >= q.length){
System.out.println("The queue is full");
return;
}
q[length] = s;
length++;
}
public String dequeue(){
String local = q[0];
int i;
for (i = 0; i < length-1; i++){
q[i] = q[i+1];
}
q[i] = "";
length --;
return local;
}
public void myPrint(){
int i;
System.out.printf("[");
for(i=0; i < length-1; i++){
System.out.printf(q[i] + ", ");
}
System.out.printf(q[i]);
System.out.printf("]\n");
}
public static void main(String[] args){
StringQueue myQ = new StringQueue(6);
myQ.enqueue("Aaron");
myQ.enqueue("Nikolo");
myQ.enqueue("Ryan");
myQ.enqueue("Lucas");
myQ.enqueue("Devin");
myQ.enqueue("Mustaph");
myQ.myPrint();
}
}
//look up circular queue methods