added iter method to stack and queue #118
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
which returns an array with Stack elements in LIFO order/Queue elements in FIFO order.
This is essentially the fix for #116
This PR only adds the iter method with LIFO semantics for Stack and FIFO semantics for queue.
The Stacks and Queues are still parametrized by the underlying container (Deque{T}) than the element type. I think these datastructures should ideally be parametrlized by the element type, and not implementation details which causes an abstraction leak.
However I have not changed this in this PR's code, only added an iter method which returns an array with the elements in an order that makes sense for the datastructure - LIFO for Stack and FIFO for queue. I finally went with @lindahua 's concept than by implementing next() etc because this makes it easier to add alternate traversal schemes later.