![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
CircularArray/CircularArray.cpp
- Committer:
- aburch1
- Date:
- 2017-04-21
- Revision:
- 71:a935e4b88ad8
- Parent:
- 65:3723d2729b68
- Child:
- 72:ef4a4e3089c1
File content as of revision 71:a935e4b88ad8:
#include "CircularArray.h" #include <stdio.h> #include <ctype.h> /* Constructor */ CircularArray::CircularArray(int limit) { maxSize = limit; array = new Measure[maxSize]; firstValue = 0; currentSize = 0; } void CircularArray::pushValue(Measure _measure) { if(currentSize >= maxSize) { firstValue++; currentSize--; } int nextSpace = nextSpace(); array[nextSpace] = _measure; currentSize++; } void CircularArray::readX(int x) { if(x > currentSize) { x = currentSize; printf("Changed print amount to currentSize"); } int currentElement = nextSpace() - x; if(currentElement < 0) { currentElement += maxSize; } for(int i = 0; i < x; i++) { char *ptr = array[currentElement].date.ToString(); printf("\n\r%i. %s T: %f | H: %f | P: %f |",i,ptr , array[currentElement].temperature, array[currentElement].humidity, array[currentElement].pressure); currentElement++; currentElement = currentElement % maxSize; } } void CircularArray::readAll() { readX(currentSize); } void CircularArray::deleteX(int x) { if(x >= maxSize) { deleteAll(); } else { firstValue += x; currentSize -= x; firstValue = firstValue % maxSize; if(currentSize <= 0) { deleteAll(); } } } void CircularArray::deleteAll() { currentSize = 0; } int CircularArray::getSize() { return currentSize; } int CircularArray::nextSpace() { int nextSpace = firstValue + currentSize; nextSpace = nextSpace % maxSize; return nextSpace; }