在上一篇文章中,咱們詳細介紹了棧結構,並結合Stack源碼進行了分析,相關文章你們能夠點擊這裏回看個人博客:線性表數據結構解讀(三)棧結構Stackjava
隊列的定義
隊列是一種插入和刪除分別在兩端進行操做的線性表,一端進行插入操做,一端進行刪除操做。數組
隊列的特色
咱們把進入隊列端稱爲隊列的對尾,用rear表示;離開隊列的一端成爲隊列的頭,用front表示,即在隊列的頭進行刪除操做。markdown
滿隊列
當一個隊列rear指向最後一個位置時,不可以再進行插入操做,成爲滿隊列狀態。數據結構
空隊列
當front的位置在rear後面時,表示隊列中沒有元素能夠離開,說明隊列是空狀態。app
循環隊列
隊列的頭尾詳解的順訊存儲結構稱爲循環隊列this
隊列的缺點
隊列空和滿均可能出現假空和假滿的狀態spa
棧的存儲結構
● 順序隊列
隊列在順序存儲結構下所獲得的結構,成爲順序隊列。順序棧類相似於數組,所以可使用數組實現順序棧的相關運算。.net
● 鏈式隊列
隊列在鏈式存儲結構下所獲得的結構,稱爲鏈隊。鏈式隊列相似於指針,在java中能夠經過類的對象引用實現指針運算。指針
在Android中,咱們常見具備表明性的隊列結構爲Queue,可是Queue確是一個接口,具體源碼以下。rest
public interface Queue<E> extends Collection<E> { /** * 添加方法 * Inserts the specified element into this queue if it is possible to do so * immediately without violating capacity restrictions, returning * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt> * if no space is currently available. * @param e the element to add * @return <tt>true</tt> (as specified by {@link Collection#add}) * @throws IllegalStateException if the element cannot be added at this * time due to capacity restrictions * @throws ClassCastException if the class of the specified element * prevents it from being added to this queue * @throws NullPointerException if the specified element is null and * this queue does not permit null elements * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ boolean add(E e); /** * 入隊方法 * Inserts the specified element into this queue if it is possible to do * so immediately without violating capacity restrictions. * When using a capacity-restricted queue, this method is generally * preferable to {@link #add}, which can fail to insert an element only * by throwing an exception. * @param e the element to add * @return <tt>true</tt> if the element was added to this queue, else * <tt>false</tt> * @throws ClassCastException if the class of the specified element * prevents it from being added to this queue * @throws NullPointerException if the specified element is null and * this queue does not permit null elements * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ boolean offer(E e); /** * 移除元素方法 * Retrieves and removes the head of this queue. This method differs * from {@link #poll poll} only in that it throws an exception if this * queue is empty. * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ E remove(); /** * 出隊方法 * Retrieves and removes the head of this queue, * or returns <tt>null</tt> if this queue is empty. * @return the head of this queue, or <tt>null</tt> if this queue is empty */ E poll(); /** * 獲取某一個元素方法 * Retrieves, but does not remove, the head of this queue. This method * differs from {@link #peek peek} only in that it throws an exception * if this queue is empty. * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ E element(); /** * 出隊並刪除掉 * Retrieves, but does not remove, the head of this queue, * or returns <tt>null</tt> if this queue is empty. * @return the head of this queue, or <tt>null</tt> if this queue is empty */ E peek(); }
既然是接口,那麼就有實現類,我以前給你們分析的LinkedList源碼正是實現了該接口,具體能夠查閱我以前的博客線性表數據結構解讀(二)鏈式存儲結構LinkedList