js下实现队列
来源:互联网 发布:参考文献 网络 编辑:程序博客网 时间:2024/05/16 08:48
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>dedicated web worker</title></head><body></body><script> /*--------------Queue类的定义和测试代码----------------*/function Queue(){ this.dataStore = []; this.enqueue = enqueue; this.dequeue = dequeue; this.front = front; this.back = back; this.toString = toString; this.empty = empty;this.length=Length;}//入队,就是在数组的末尾添加一个元素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 Length(){ return this.dataStore.length;}function toString(){ var retStr = ""; for (var i=0; i<this.dataStore.length; ++i) { retStr += this.dataStore[i] + " " } return retStr;}//判断数组是否为空function empty(){ if(this.dataStore.length == 0){ return true; }else{ return false; } }//返回数组中元素的个数function count(){ return this.dataStore.length;}var q = new Queue();q.enqueue("Meredith");q.enqueue("Cynthia");q.enqueue("Jennifer");document.write(q.toString());document.write('<br>');document.write("Front of queue is:" + q.front()+" le "+q.length());console.log(q.dequeue()) ;console.log(q.length()) ;console.log(q.front()) ;document.write('<br>');document.write("Back of queue is:" + q.back());</script></html>
阅读全文
0 0
- js下实现队列
- JS 异步队列的实现
- js实现prim+优先队列
- 数据结构:用JS实现队列
- js-队列使用-循环队列实现击鼓传花
- js数组实现队列和栈
- JS数组实现队列和堆栈
- 基于js的简单队列实现
- js数组实现队列和栈
- Wince环境下实现收发消息队列
- linux 下内核中消息队列实现
- 关于vxWorks下消息队列的实现
- PHP下用Memcache 实现消息队列
- Linux下Redis+crontab实现任务队列
- Linux C下链队列的实现
- linux下运用c实现队列调度
- js 下 map 的实现
- js下的sleep实现
- CentOS7安装配置JDK7和Tomcat7及开启启动
- js中对象
- 什么是区块链?
- table列的相同单元格合并
- Android音频驱动-ASOC之Sound Card注册
- js下实现队列
- flannel 的连通与隔离
- HDU
- ICO使用区块链技术进行交易、支付、审计、铸币全过程解析
- 转载一个webview开车指南以及实际项目中的使用
- Dijkstra算法-单源最短路径—C
- 一个好中医就是一座全科医院
- iOS 主题-皮肤之 SakuraKi
- Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块