Reputation: 95
It is said everywhere that "In a stack, the priority of each inserted element is monotonically increasing" But in stack, every new element has a priority higher than the previous element. So, when implemented as Priority Queue, if 2 subsequent elements have same priority (as per the definition of monotonic), the deletion will not adhere to Stack's LIFO policy but FIFO policy.
Shouldn't the priority be strictly increasing?
Thanks in advance !!
Upvotes: 1
Views: 87
Reputation: 55619
Yes, I believe "monotonically" rather than "strictly" is incorrect.
Monotonically increasing could work for a stack if you assume that, between two elements with the same priority, the one inserted earlier will always be after the other. But this assumption isn't made in a literature I've seen on the subject, and will need to be swapped around to simulate a queue (the one inserted earlier will need to be before the other).
Upvotes: 1