首先实现一个简单的链表队列,头插元素,尾删元素。
package com.zwj;
import java.util.concurrent.atomic.AtomicInteger;
public class MyQueue<T> {
private volatile node head;
private volatile node tail;
private volatile AtomicInteger size = new AtomicInteger(0);
private int length;
public MyQueue(T t) {
head = create(t);
tail = head;
size.incrementAndGet();
}
class node<T> {
public T value;
public node nex;
public node(T t) {
this.value = t;
this.nex = null;
}
}
private node create(T t) {
node root = new node(t);
root.nex = null;
return root;
}
public Boolean put(T t, int capality) {
if (tail != null && size.get() < capality) {
node newNode = new node(t);
tail.nex = newNode;
tail = ta