First an overview of what I am trying to do:
Every time a user presses a key, I am recording the current time and once I have more than 5 records I need to calculate the average time between the key presses (whilst only retaining the last 5 – 10 key presses).
When I first sat down and looked at this problem I thought, easy, I will use a stack and simply keep it at less than 10 items.
Question:
- How do I ensure that a stack only has a maximum of ten values in it?
(date time type) - How do I find the average time between each of the date times stored in the stack?
Thanks
Dan
Don’t use a Stack, but use a Queue with limited capacity. This can be achieve by something like :