Java佇列實現

2021-06-21 07:21:32 字數 1110 閱讀 1385

佇列陣列實現:佇列長度有限,但是考慮到平時一般都使用有界佇列,這應該也不算是個缺點

public class queue 

public void push(object obj) throws exception

public object pop() throws exception

public object peek() throws exception

public int size()

public boolean isempty()

public boolean isfull()

}

插入和刪除的時間複雜度都為o(1)

佇列雙端鍊錶實現

public class firstlastlist 	}	

private data first = null;

private data last = null;

public void insertlast(object obj)else

last = data; }

public object deletefirst() throws exception

public void display()

system.out.print("\n");

}}

public class firstlastlistqueue 

public object pop() throws exception

public void display()

public static void main(string args) throws exception

}

first -> last : | 1 | 2 | 3 | 

1first -> last : | 2 | 3 |

first -> last : | 2 | 3 | 4 |

長度不受限制並且插入和刪除的時間複雜度都為o(1)

Java實現佇列

先寫乙個介面,確定要實現的功能package myqueue public inte ce myqueue順序佇列 package myqueue public class queuearray implements myqueue override public void clear overri...

佇列 Java實現

佇列主要的特性是先進先出 fifo 先看一下佇列的基本結構 private object data null private int maxsize 佇列的容量 private int front 頭 private int rear 尾data 用來存放佇列中的值 public myqueue i...

Java實現佇列

佇列 queue 是一種只允許在一端進行插入操作,而在另一端進行刪除操作的線性表。佇列是一種先進先出 first in first out 的線性表,簡稱fifo。允許插入的一端稱為隊尾,允許刪除的一端稱為隊頭 鍊錶方式實現佇列 author victertian version v1.0 date...