雙向迴圈煉表示意圖:
雙向迴圈鍊錶實現**:
public class
doublelink }
private int size;//鍊錶長度
public nodehead;//頭節點
/** * constructor
*/public doublelink()
/*** 獲取鍊錶的長度
* @return
*/public int size()
/*** 判斷鍊錶是否為空
* @return
*/public boolean isempty()
/*** 驗證索引的合法性
* @param index
*/public void validateindex(int index)
return;
}/**
* 獲取位置為index的節點
* @param index
* @return
*/private nodegetnode(int index)
return cur;
}nodecur = head.prev;
int newindex = size - index - 1;
for (int i = 0; i < newindex; i++)
return cur;
}/**
* 獲取位置為index的節點值
* @return
*/public e get(int index)
/*** 獲取第乙個節點的值
* @return
*/public e getfirst()
/*** 獲取最後乙個節點的值
* @return
*/public e getlast()
/*** 插入節點
* @param index
* @param value
*/public void insert(int index, e value)
nodenode = getnode(index);
nodecur = new node(value, node.prev, node);
node.prev.next = cur;
node.prev = cur;
size++;
return;
}/**
* 新增到鍊錶的頭部
* @param value
*/public void addfirst(e value)
/*** 新增節點到鍊錶的尾部
* @param value
*/public void addlast(e value)
/*** 刪除位置為index的節點
* @param index
*/public void delete(int index)
/*** 刪除第乙個節點
*/public void deletefirst()
/*** 刪除最後乙個節點
*/public void deletelast()
}
鍊錶 java實現雙向鍊錶
前面已經總結了單向鍊錶,有興趣的兄弟可以進我部落格看一下。大家對比就可以看出,實現同樣的功能單向鍊錶要比雙向鍊錶痛苦的多。所以呀不斷地總結前輩留下的東西,是社會進步的基礎呀。可以直接看linkedlist的原始碼,其就是個雙向鍊錶。一 雙向鍊錶的結構。1 首先節點的結構,其中包含本節點內容,同時需要...
java實現雙向鍊錶
實現類,只實現了幾個比較簡單的功能 package 鍊錶.雙向鍊錶 program 資料結構 description 雙向鍊錶的實現 author zhongyusen create 2019 05 31 21 45 public class mylinklist public void add o...
C 實現雙向迴圈鍊錶
雙向迴圈鍊錶 除錯正常,所有功能均測試 節點類 template class listnode listnode type d,listnode n nullptr,listnode p nullptr data d next n prev p void setdata type d 雙向迴圈鍊錶 ...