日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java循环队列配对_循环队列 链式队列 的jJAVA实现

發布時間:2024/8/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java循环队列配对_循环队列 链式队列 的jJAVA实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對節點的移除插入刪除操作,一定要注意在表頭和表尾邊界進行處理的過程 出隊列時

注意只有一個元素的情況,此時隊尾和對頭指針應該都為空,別忘了修改隊尾指針。

class CircleQueue

{

private final int DEFAULTCAPACITY=4;

private T[]array;

private int head;

private int tail;

private int size;

private int currentCapacity;

public CircleQueue()

{

array=(T[])new Object[DEFAULTCAPACITY];

head=0;

currentCapacity=DEFAULTCAPACITY;

tail=0;

}

public int size()

{

return size;

}

public T front()

{

if(isEmpty())

return null;

return array[head];

}

public boolean isEmpty()

{

if(head==tail)

return true;

return false;

}

public boolean isFull()

{

if((tail+1)%currentCapacity==head)

return true;

return false;

}

public void enqueue(T a)

{

if(isFull())

return ;

array[tail++]=a;

tail=tail%currentCapacity;

size++;

}

public T dequeue()

{

if(isEmpty())

return null;

size--;

T a= array[head++];

head=head%currentCapacity;

return a;

}

}

/**

* 本結構體鏈表為雙向鏈表

*

*/

class LinkedQueue{

private static class Node{

private T e;

private Node pre;

private Node next;

public Node(T e,Node pre,Node next)

{

this.e=e;

this.pre=pre;

this.next=next;

}

}

private Node head;

private Node tail;

private int size;

public LinkedQueue()

{

head=new Node(null,null,null);

tail=head;

size=0;

}

public boolean isEmpty()

{

if(size==0)

return true;

return false;

}

public int size()

{

return size;

}

public T front()

{

if(isEmpty())

return null;

return head.e;

}

public T dequeue()

{

if(isEmpty())

return null;

T a=head.e;

head=head.next;

if(size==1)

tail=head;

size--;

return a;

}

public void enqueue(T e)

{

tail=new Node(e,tail,null);

if(size==0)

head=tail;

size++;

tail.pre.next=tail;

}

}

public class Queue {

public static void main(String args[])

{

LinkedQueue a=new LinkedQueue();

a.enqueue(2);

a.enqueue(3);

a.enqueue(4);

a.enqueue(5);

System.out.println(a.size()+" ");

System.out.println(a.dequeue()+" ");

System.out.println(a.size()+" ");

}

}

總結

以上是生活随笔為你收集整理的java循环队列配对_循环队列 链式队列 的jJAVA实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。