You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
883 B

#include "queue.h"
Queue::Queue() {
init();
}
void Queue::init(){
}
void Queue::push(byte value) {
list[writeIndex] = value;
writeIndex = (writeIndex + 1) % sizeof(list);
}
byte Queue::pop() {
byte value = list[readIndex];
list[readIndex] = 0;
readIndex = (readIndex + 1) % sizeof(list);
return value;
}
byte * Queue::clone() {
for(int i=0; i<sizeof(list); i++){
int j = writeIndex % sizeof(list);
queue[i] = list[j];
}
return queue;
}
byte Queue::lookup(byte index){
return list[(index + writeIndex) % sizeof(list)];
}
byte Queue::getMax(){
byte maxValue = 0;
for (int i=0;i<sizeof(list); i++){
if(list[i] > maxValue) maxValue = list[i];
}
return maxValue;
}
byte Queue::getMin(){
byte minValue = 255;
for (int i=0;i<sizeof(list); i++){
if(list[i] < minValue && list[i] > 0) minValue = list[i];
}
return minValue;
}