Why I'm wrong?
LAST IN FIRST OUT is using the structure, that is, when I need to read
the datastructure I Pop the Stack. When I want to insert a element i
need to Push in the Stack.
I not need a Queue.
I want a Stack that "record" the last n element pushed. The oldest must
be overwrite when pushing element when the count exceeds limit.
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.
So the use is LIFO.
PS ha scritto:
> > Hi,
> >
[quoted text clipped - 17 lines]
>
> > It is possbible with this Objet? Or I must make my struct?
Peter Duniho - 23 Nov 2006 19:22 GMT
> [...]
> 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