M
mark4asp
Stack of limited size containing unique items?
Hi guys,
How would I implement a stack of limited size containing unique items?
For example. Suppose my stack has [3,5]. I add 2 to it and it is now
[3,5,2]. Now I want to add 5 to the unique item stack so it should
now be: [3,2,5]. The item added is pulled from the stack, then pushed.
The stack should also have a maximum size of 4 items. I add 4 and 7
respectively. It becomes: [3,2,5,4] then, after adding 7: [2,5,4,7].
The first item is dropped when the stack is at maximum capacity and a
new item added. Should this be a queue rather than a stack? I said
'stack' because, apart from the limited size behavior of the oldest
item being dropped in favour of the new item, I want it to have the
FILO behavior of a conventional stack.
Hi guys,
How would I implement a stack of limited size containing unique items?
For example. Suppose my stack has [3,5]. I add 2 to it and it is now
[3,5,2]. Now I want to add 5 to the unique item stack so it should
now be: [3,2,5]. The item added is pulled from the stack, then pushed.
The stack should also have a maximum size of 4 items. I add 4 and 7
respectively. It becomes: [3,2,5,4] then, after adding 7: [2,5,4,7].
The first item is dropped when the stack is at maximum capacity and a
new item added. Should this be a queue rather than a stack? I said
'stack' because, apart from the limited size behavior of the oldest
item being dropped in favour of the new item, I want it to have the
FILO behavior of a conventional stack.