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>

    //效果

  • 相关阅读:
    tomcat集群--单tomcat多实例
    nginx 轮询模式 nginx_upstream_jvm_route 插件安装
    nginx 反向代理配置
    HP SiteScope安装
    visualVM远程监控JVM
    robotium 测试APK<一> 建立测试工程
    jmeter的http post请求与测试Java请求
    第 10 天
    第 1~8 天复习
    第 9 天 python操作mysql数据库
  • 原文地址:https://www.cnblogs.com/yzenet/p/4518765.html
Copyright © 2011-2022 走看看