檢視linkedlist原始碼:
1、實現棧
後進先出,插入和彈出操作都在前端,對應**:
public void push(e e)
/*** pops an element from the stack represented by this list. in other
* words, removes and returns the first element of this list.
** this method is equivalent to .
** @return the element at the front of this list (which is the top
* of the stack represented by this list)
* @throws nosuchelementexception if this list is empty
* @since 1.6
*/public e pop()
2、實現佇列
先進先出,插入在前端,彈出在後端,通過乙個雙向指標,末尾操作,即是header.previour操作
public e poll()
public boolean offer(e e)
public boolean add(e e)
private entryaddbefore(e e, entryentry)
使用LinkedList實現安全佇列
使用 wait notify 實現乙個佇列,佇列有2個方法,add 和 get add方法往佇列中新增元素,get方法往佇列中獲得元素。佇列必須是執行緒安全的。如果get執行時,隊列為空,執行緒必須阻塞等待,直到有佇列有資料。如果add時,佇列已經滿,則add執行緒要等待,直到佇列有空閒空間。使用l...
手工實現LinkedList
參照其底層 按照自己的理解實現了linkedlist的一些基本功能。如果對c和c 指標了解一下,理解起來非常快。package cn.liu.mylinkedlist 結點 public class node 構造器,來傳資料 public node object element package c...
手工實現linkedList
鍊錶結構就像一根鏈條一樣,環環相扣。每一環 node entry 都由next previous,element 存放資料的地方 第乙個的next 是第二個,第二個的next是第三個,直到最後乙個的next 可以為null 最後第乙個的previous 是最後第二個,最後第二個的previous是最...