zoukankan      html  css  js  c++  java
  • js之队列01


    <!
    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>队列</title> <script type="text/javascript"> //开始准备实现队列 function Queue() { this.dataStore = []; this.enqueue = enqueue; this.dequeue = dequeue; this.front = front; this.back = back; this.toString = toString; this.empty = empty; } //入队 function enqueue(element) { this.dataStore.push(element); } //出队 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 empty() { if(dataStore.length == 0){ return true; } else { return false; } } //测试 //构造对象 var q = new Queue(); //入队 q.enqueue("A"); q.enqueue("B"); q.enqueue("C"); q.enqueue("D"); //打列元素 console.log(q.toString()); //队首 console.log("Front of queue: " + q.front()); //道尾 console.log("Back of queue: " + q.back()); //出队 q.dequeue(); //队首 console.log("Front of queue: " + q.front()); //道尾 console.log("Back of queue: " + q.back()); //打列元素 console.log(q.toString()); </script> </head> <body> </body> </html>

    //效果

  • 相关阅读:
    scrollView(3)-相册浏览简单的缩放
    ScrollView(2)轮播图-点击跳转
    定制单元格-cell
    模态视图present
    将博客搬至CSDN
    VBS进行http请求及JSON数据的读取和生成
    igraph安装(R/Python)
    teiid入门
    漫谈设计模式
    MapReduce实例-基于内容的推荐(一)
  • 原文地址:https://www.cnblogs.com/yzenet/p/4518765.html
Copyright © 2011-2022 走看看