-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntQueue.java
More file actions
124 lines (100 loc) · 1.88 KB
/
IntQueue.java
File metadata and controls
124 lines (100 loc) · 1.88 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class IntQueue {
private int[] q;
private int front=0;
private int back=0;
public IntQueue(int size)
{
q = new int[size];
}
void put(int i){
q[back]=i;
back= (back+1)%q.length;
if(front==back) resize();
}
int get() {
int temp = q[front];
front = (front+1)%q.length;
return temp;
}
boolean isEmpty()
{
return front==back;
}
private void resize()
{
//to be completed
}
int size()
{
return Math.abs(front-back);
}
/*
* getAll
* gets the entire queue
* @author Allegra Simon and Alex Fisher
*/
int[] getAll()
{
int[] fullQueue = new int[this.size()];
for(int i=0; i<this.size(); i++)
{
fullQueue[i] = q[i];
this.get();
}
return fullQueue;
}
int[] get(int x)
{
int[] mini = new int[x];
int counter=0;
while(counter<x)
{
mini[counter++]= this.get();
}
return mini;
}
/*
*Subque
*Allows the user to create a subque.
*@author Zachary Buttenwieser
*@author Adam Phillips
*@param s the place you want to start
*@param e the place you want to end
*/
public Queue subQ(int s, int e) {
IntQueue subQ = new IntQueue();
if(s<e){
for (int i = s; i < e; i++){
subQ.put(q[i]);
}
}
else if (s> e ) {
for (int i = s; i < q.length; i++) {
subQ.put(q[i]);
}
for (int i = 0; i < e; i++) {
subQ.put(q[i]);
}
}
return subQ;
}
/*
* Pop X number of ints
* Ask for X
* Run pop X number of times
* Move the popped ints into new array
* return new array
* @author James Shao
* @author Ben Ginzberg
*/
public int[] popX(int x)
{
int[] getX = new int[x]; //set return array length to equal number of items popped
for(int i=0; i<x; i++) //run loop x number of times
{
getX[i]=q[i]; //put pop int into return array
this.get();
}
return getX;
}
}