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
    
  
  
    
  | /** | |
| * 初始化栈结构 | |
| */ | |
| var MyStack = function () { | |
| this.queue = new MyQueue() | |
| this.size = 0 | |
| }; | |
| /** | |
| * 新元素入栈 | 
  
    
      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
    
  
  
    
  | /** | |
| * 基于数组实现一个栈结构 :先入后出 | |
| * js相对于其他语言(c或java)实现栈结构更加简洁。得益于js里的数组操作api丰富 | |
| */ | |
| function Stack() { | |
| this.arr = [] | |
| } | |
| // 新元素入栈 | |
| Stack.prototype.push = function (val) { | 
  
    
      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
    
  
  
    
  | var arr = [6, 4, 5, 2, 9, 3, 8, 7, 1] | |
| // ① 比较 | |
| function compare(left, right) { | |
| return left > right | |
| } | |
| // ② 交换 | |
| function exchange(arr, leftIdx, rightIdx) { | |
| var temp = arr[leftIdx] |