i have a buffer sized 2000, the data to be inserted is unlimited. I want, data more than 2000 should be added from the end of the buffer, i.e. push all data from right to left and insert new data at the end of the buffer. So, what kind of algorithm or flow i should try on?
Asked
Active
Viewed 1,848 times
1 Answers
2
You want to use a FIFO, or 'Circular Buffer'. See http://en.wikipedia.org/wiki/Circular_buffer for a complete explanation, or even example code.
Depending on your actual needs, the implementation can be different. If, for example, you always need to access the 2000 items sequentially, you can omit the read pointer (as it is always one item behind the write pointer).
Edit: Queue is something similar. If you are using C++, consider http://www.cplusplus.com/reference/stl/queue/

Rudolf Mühlbauer
- 2,511
- 16
- 18