java双端队列ArrayDeque

来源:互联网 发布:恩施天勤网络 编辑:程序博客网 时间:2024/04/29 21:48

java中双端队列为ArrayDeque,

import java.util.ArrayDeque;

其使用方法同队列类似, 不过有几个方法是双端队列特有的:

addFirst(E e)//Inserts the specified element at the front of this deque.//将指定元素插入对头

addLast(E e)//Inserts the specified element at the end of this deque.//将指定元素插在队尾//Retrieves, but does not remove, the first element of this deque.//获取队头元素,不删除只是查看
getFirst()

//获取队尾元素,不删除只是查看
//Retrieves, but does not remove, the last element of this deque.

getLast()

//查看队头元素,不删除只是查看,队列空返回null
peekFirst()

//查看队尾元素,不删除只是查看,队列空返回null
peekLast()

//删除队头元素,返回值为删除的那个元素
pollFirst()

//删除队尾元素,返回值为删除的那个元素
pollLast()

//注意这里:
//从队尾处插入元素
add();

//从队头插入元素
push()

在此做下记录。


0 0
原创粉丝点击