Create a new class called pseudo queue.
- Do not use an existing Queue.
- Instead, this PseudoQueue class will implement our standard queue interface (the two methods listed below),
- Internally, utilize 2 Stack instances to create and manage the queue
Methods: enqueue Arguments: value
-
Inserts a value into the PseudoQueue, using a first-in, first-out approach. dequeue Arguments: none
-
Extracts a value from the PseudoQueue, using a first-in, first-out approach.
-
This will use code from Stack
Figjam Link for Code Challenge 11-- to navigate the image embedded above
In my code, I used two stacks within the enqueue method to simulate a queue. I also had the class of PseudoQueue hold a stack called pseudo_queue that I could update for each instance of the PseudoQueue class.
Time: O(1)
- because only deals with one node at a time for all of these methods, since the nodes being accessed are only on the top, and one at a time.
Space: O(n)
- because it will be the amount of space for each of the nodes in each stack is only stored once, and at most 2n if there are elements stored in two stacks during method operations.
Terminal command for general main module: python3 -m pseudo_queue.pseudo_queue
Terminal command for testing in pytest: python3 -m pytest pseudo_queue/
