zoukankan      html  css  js  c++  java
  • 优先队列

    function PriorityQueue () {
        this.collection = [];
        this.printCollection = function() {
          console.log(this.collection);
        };
        // Only change code below this line
        this.enqueue = function() {
            if (this.isEmpty()){ 
                this.collection.push(arguments[0]);
            } else {
                var added = false;
                for (var i=0; i<this.collection.length; i++){
                     if (arguments[0][1] < this.collection[i][1]){ //checking priorities
                        this.collection.splice(i,0,arguments[0]);
                        added = true;
                        break;
                    }
                }
                if (!added){
                    this.collection.push(arguments[0]);
                }
            }
        }
        
        this.dequeue = function() {
            var ans = this.collection.shift()
            return ans[0];
        }
        
        this.front = function() {
            return this.collection[0];
        }
        
        this.size = function() {
            return this.collection.length;
        }
        
        this.isEmpty = function() {
            return this.collection.length > 0 ? false : true;
        }
        // Only change code above this line
    }
  • 相关阅读:
    HDU 1247
    [转载]亲密接触VC6.0编译器
    [转载]你该学什么程序语言
    ACE学习2009116
    新东方英语学习二
    电脑族吃什么比较好
    爱默生生活的准则
    成大事必备9种能力9种手段9种心态
    [转载]句柄和指针
    关于WM_CREATE消息
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/8276536.html
Copyright © 2011-2022 走看看