Homer_simpson @ Sun Jul 03, 2011 6:30 pm wrote:
It has been a while since I have done any programming in c++ and I've become a bit rusty. =S
here's the explanation of the problem:
I have an array of 800 real numbers. I read a new data point to be added to the array from the serial port and i need to push all the datapoints on the array back by one and consequently get rid of the last datapoint to make room for the new one. now I realize that i can push every single data point down using a loop and add the new datapoint but I don't think that this is the best way of achieving the task.
I hope I explained it properly.
Any suggestions to point me in the right direction are appreciated.thanks
By your description I can't quite tell whether you're looking for a stack-type structure or queue, but to me it sounds like you're looking for a queue (think of a conveyor belt; first in = first out). If so, take a look at the queue STL container. Otherwise, a vector makes for a nice intuitive stack structure with constant-time element access.