"SP" <da************@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
[...]
I need to use this in a Undo scenario. I want to record the action put
them in a Stack. When I make a action I make push,when redo a Pop. If a
make many action without redo, I want to limit my Stack. I want also
that new entry have priority, and oldest can be overwrite.
I'm not sure why people are giving you a hard time about your use of the
term "stack". It seems appropriate enough, even if you do want your stack
to allow old elements to be able to fall off the other end.
Anyway, seems to me the simplest way to implement your "stack" is to use
some form of a linked list (like, maybe using the LinkedList class :) ).
Designate one end of the list as the top of the stack, and the other as the
bottom. A double-linked list (such as LinkedList) allows for fast changes
to the list, including retrieving the first and last elements quickly, as
well as adding or removing elements.
So, when you want to push onto the stack, you simply add the element at the
end you've chosen for the top of your stack. If the length of the stack
exceeds your limit, you remove the element at the end that you've chosen for
the bottom of your stack.
Pete