1.访问 O(N)
从队列头查到队列尾
2.搜索 O(N)
从头到尾
3.插入 O(1)
必须在末尾端插入
4.删除 O(1)
1.创建队列
Queue<Integer> queue = new LinkedList<>();
2.添加元素
queue.add(1);
3.获取即将出队的元素
int temp1 = queue.peek();
4.删除即将出队的元素
//获取要出列的元素,并删除 int temp2 = queue.poll(); System.out.println(temp2); System.out.println(queue.toString());
5.判断队列是否为空 O(1)
//true or false queue.isEmpty()
6.队列长度 O(1)
queue.size()
7.遍历队列(边删除边遍历) O(N)
while(!queue.isEmpty()){ int temp=queue.poll(); System.out.println(temp); }
力扣933题