java代码实现队列
编程技术  /  houtizong 发布于 3年前   79
java代码实现队列
单向队列:
import java.util.LinkedList;//单向队列public class Queue {public Queue() {}private LinkedList list = new LinkedList();public void put(Object v) {list.addFirst(v);}public Object get() {return list.removeLast();}public boolean isEmpty() {return list.isEmpty();}}
双向队列:
import java.util.Collection;import java.util.Iterator;import java.util.LinkedList;// 双向队列public class DQueue implements Collection {private LinkedList lists;public DQueue() {lists = new LinkedList();}public void put_front(Object v) {lists.addFirst(v);}public void put_back(Object v) {lists.addLast(v);}public Object get_front() {return lists.removeFirst();}public Object get_Back() {return lists.removeLast();}public boolean isEmpty() {return lists.isEmpty();}public int size() {return lists.size();}public boolean contains(Object o) {return lists.contains(o);}public Iterator iterator() {return lists.iterator();}public Object[] toArray() {return lists.toArray();}public Object[] toArray(Object a[]) {return lists.toArray(a);}public boolean add(Object o) {lists.addLast(o);return true;}public boolean remove(Object o) {return lists.remove(o);}public boolean containsAll(Collection c) {return lists.containsAll(c);}public boolean addAll(Collection c) {return lists.addAll(c);}public boolean removeAll(Collection c) {return lists.removeAll(c);}public boolean retainAll(Collection c) {return lists.retainAll(c);}public void clear() {lists.clear();}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接