Created
          March 24, 2022 07:32 
        
      - 
      
 - 
        
Save d-rat/0da1cd8ba6c174e7f725873fdf1a2efa to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class QueueStack { | |
| constructor() { | |
| this.q = []; | |
| } | |
| push(val) { | |
| let size = this.q.length; | |
| this.q.push(val); | |
| while (size--) { | |
| this.q.push(this.q.shift()); | |
| } | |
| } | |
| pop() { | |
| if (!this.q.length) return null; | |
| return this.q.shift(); | |
| } | |
| peek() { | |
| if (!this.q.length) return null; | |
| return this.q[0]; | |
| } | |
| isEmpty() { | |
| return this.q.length === 0 | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment