SOURCE

var priorityQueue = function(){
  var items = [];
  //辅助类
  var QueueItem = function(element,priority){
    this.element = element
    this.priority = priority
  }
  this.enqueue = function(element,priority){
    var queueItem = new QueueItem(element,priority)
    var added = false;
    for(var i=0;i<items.length;i++){
      if(queueItem.priority > items[i].priority){
         items.splice(i,0,queueItem)
         added = true;
         break;
      }
    }
    if(!added){
      items.push(queueItem);
    }
  }
  this.getItems = function(){
    return JSON.stringify(items);
  }
}

var pq = new priorityQueue();
pq.enqueue('小黑',10);
pq.enqueue('小明',12);
pq.getItems();
console 命令行工具 X clear

                    
>
console