zoukankan      html  css  js  c++  java
  • js:数据结构笔记4--队列

    队列是一种特殊的列表,数据结构为FIFO;

    定义:

    function Queue() {
       this.dataStore = [];
       this.enqueue = enqueue;
       this.dequeue = dequeue;
       this.front = front;
       this.back = back;
       this.count = count;
       this.toString = toString;
       this.isEmpty = isEmpty;
    }
    function enqueue(elem) {
       this.dataStore.push(elem);
    }
    function dequeue() {
       return this.dataStore.shift();
    }
    function front() {
       return this.dataStore[0];
    }
    function back() {
       return this.dataStore[this.dataStore.length - 1];
    }
    function toString() {
       var retStr = "";
       for(var i = 0; i < this.dataStore.length; ++i) {
          retStr += this.dataStore[i] + "
    ";
       }
       return retStr;
    }
    function count() {
       return this.dataStore.length;
    }
    function isEmpty() {
       if(this.dataStore.length === 0) {
          return true;
       } else {
          return false;
       }
    }
    

    例子:

    舞伴分配: demo

    基数排序:demo

    优先队列:demo

  • 相关阅读:
    0523注册审核
    0520三级联动
    0519考试练习题
    0516ajax
    mysql 高级查询
    mysql
    HTML的格局与布局
    css样式表
    HTML表单
    HTML
  • 原文地址:https://www.cnblogs.com/jinkspeng/p/4028170.html
Copyright © 2011-2022 走看看