Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 2.06 KB

File metadata and controls

54 lines (33 loc) · 2.06 KB

Pseudo Queue with 2 Stacks

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

Whiteboard Process

Code Challenge 11: figjam image, link below

Figjam Link for Code Challenge 11-- to navigate the image embedded above

Approach & Efficiency

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.

Solution

Terminal command for general main module: python3 -m pseudo_queue.pseudo_queue

Terminal command for testing in pytest: python3 -m pytest pseudo_queue/

Terminal test executions

Code Links

PseudoQueue

Tests of PseudoQueue