zoukankan      html  css  js  c++  java
  • js实现队列互联网机顶盒实战应用

    /*
    * 队列
    */
    Dare.Queue = function () {
      this.list = new Dare.LinkedList();//链表
    };
    Dare.extend(Dare.Queue, Dare);
    /*
    * 入队
    */
    Dare.Queue.prototype.enQueue = function (data) {
      if (data == null) return;
      var linkedListNode = new Dare.LinkedListNode();
      linkedListNode.data = data;
      this.list.appendNode(linkedListNode);
    };
    /*
    * 出队
    */
    Dare.Queue.prototype.deQueue = function () {
      if (this == null) return;
      var linkedListNode = new Dare.LinkedListNode();
      var data = null;
      this.list.start();//指针指向队头
      linkedListNode = this.list.nextNode();
      data = this.list.getNodeData(linkedListNode);
      this.list.moveNode(linkedListNode);
      return data;
    };
    /*
    * 队列长度
    */
    Dare.Queue.prototype.sizeQueue = function () {
      if (this == null) return;
      return this.list.getLength();
    };
    /*
    * 队列是否空
    */
    Dare.Queue.prototype.isEmpty = function () {
      if (this == null) return;
      return this.list.isempty();
    };

     调用示例:

    <script type="text/javascript" src="js/linkedlistnode.js"></script>
      <script type="text/javascript" src="js/linkedlist.js"></script>
      <script type="text/javascript" src="js/queue.js"></script>
      <script type="text/javascript">
        var queue = new Dare.Queue();
        function createQueue() {
          for (var i = 0; i < 7; i++) {
            var movie = {};
            movie.id = i;
            movie.name = 'movie_' + i;
            queue.enQueue(movie); //入队
          }
          showQueue(queue); //出队
          //document.write(queue.sizeQueue()); //队列长度
        }
        function showQueue(queue) {
          if (queue == null) return;
          var html = '';
          for (var i = 0; i < 7; i++) {
            var movie = {};
            movie = queue.deQueue(); //出队
            html += movie.id + "|" + movie.name + "<br>";
          }
          document.write(html);
        }
      </script>

  • 相关阅读:
    设计模式——迭代器模式
    FTP服务:FileZilla的配置和使用
    FTP服务:使用FileZilla搭建FTP服务
    FTP服务:ISS搭建服务
    javaweb项目使用RSA算法
    我在博客园的第一篇博客
    杰表打印跟乱码修改
    jsp页面角色判断
    test : 摘自 https://www.cnblogs.com/yyman001/p/3366764.html
    mybatis中sql查询不到数据单独运行sql可以获取数据
  • 原文地址:https://www.cnblogs.com/fx2008/p/2229870.html
Copyright © 2011-2022 走看看