forked from teddypee/dsa555-w18
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayqueue.h
More file actions
50 lines (48 loc) · 763 Bytes
/
Copy patharrayqueue.h
File metadata and controls
50 lines (48 loc) · 763 Bytes
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
template<class T>
class Queue{
void grow(){
T* tmp=new T[capacity_*2];
int j=front_;
for(int i=0;i<used_;i++){
tmp[i]=data[j];
j=(j+1)%capacity_;
}
delete [] data_;
data_=tmp;
capacity_=capacity_*2;
front_=0;
back_=used_;
}
T* data_;
int capacity_;
int used_;
int front_; //index of front of list
int back_; //index of where to put
//new things
public:
Queue(){
capacity_=50;
data_=new T[capacity_];
used_=0;
front_=0;
back_=0;
}
void enqueue(const T& data){
data_[back_]=data;
back_=(back_+1)%capacity_;
/* if(back_==capacity_-1){
back_=0;
}
else{
back_++;
}*/
}
void dequeue(){
front_=(front_+1)% capacity_;
}
T front() const{
return data_[front_];
}
bool empty(){
}
};