**有注釋
class listnode
public listnode
(int val)
}public class doublelinkedlist
//頭插法
public void
addfirst
(int data)
node.next = this.dummyhead.next;
this.dummyhead.next = node;
node.prev = this.dummyhead;
}//尾插法
public void
addlast
(int data)
node.prev = this.last;
this.last.next= node;
this.last = node;
}//任意位置插入,第乙個資料節點為0號下標
public void
addindex
(int index,
int data)
if(index ==0)
if(index ==
size()
)while
(index >0)
node.next = cur;
node.prev = cur.prev;
cur.prev.next = node;
cur.prev = node;
}//查詢是否包含關鍵字key是否在單鏈表當中
public boolean contains
(int key)
cur = cur.next;
}return false;
}//刪除第一次出現關鍵字為key的節點
public void
remove
(int key)
else
else
}return;}
else}}
//刪除所有值為key的節點
public void
removeallkey
(int key)
else
else}}
node = node.next;}}
//得到單鏈表的長度
public int
size()
return count;
} public void
display()
system.out.
println()
;}public void
clear()
}
雙向帶頭鍊錶的實現
pragma once typedef int dldatatype typedef struct dlistnode dlistnode,dnode void dlistinit dnode head 尾插 void dlistnodepushback dnode head,dldatatype ...
雙向迴圈帶頭節點鍊錶
include include struct dblnode typedef struct dblnode dblnode typedef struct dblnode dbllink void create link dbllink head 建立鍊錶 void create newnode db...
雙向帶環帶頭節點的鍊錶
建立乙個雙向鍊錶的節點 class listnode 關於頭插 如何將鍊錶列印出來 public void display system.out.println system.out.println 反向 system.out.print for listnode cur head.prev cur...