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
    }
  • 相关阅读:
    iOS 后台运行
    内存管理
    ios -晋级之路 如何去掉tableView多余行的横线
    ios 晋级之路- block深入
    iOS 晋级之路- 调用相机和相册的功能
    iOS开发 --定位
    学习笔记 ios开发 手势
    排序法系列-快速排序法
    计算文本的高度BoundingRectWithSize:options:context
    NSClassFromString的用法
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/8276536.html
Copyright © 2011-2022 走看看