package MyQueue;
import org.w3c.dom.ls.LSInput;
/**
* Created with IntelliJ IDEA.
* Description:
* User: czt20
* Date: 2025 -12-18
* Time: 21:53
*/
public class MyQueue {
static class ListNode{
public int val;
public ListNode pre;
public ListNode next;
public ListNode(int val) {
this.val = val;
}
}
public ListNode first=null;
public ListNode last=null;
public int usedsize=0;
ListNode cur=first;
public void offer(int val){
ListNode node=new ListNode(val);
if (isEmpty()){
first=last=node;//first和last连接就靠这里!!!!!!!!!!
}
last.next=node;
node.pre=last;
last=node;
usedsize++;
}
public int poll(){
if (first==null){
return -1;
}
ListNode curN=first;
first=first.next;
if(first!=null){
first.pre=null;
}
usedsize--;
return curN.val;
}
public int size(){
return usedsize;
}
public int peek(){
return first.val;
}
public boolean isEmpty(){
if (first==null){
return true;
}
return false;
}
}