public class doublelinkedlist
//尾插法
public void addlast(int data)
//任意位置插入,第乙個資料節點為0號下標
public boolean addindex(int index,int data)
//查詢是否包含關鍵字key是否在單鏈表當中
public boolean contain(int key)
//刪除第一次出現關鍵字為key的節點
public void remove(int key)
//刪除所有值為key的節點
public void removeall(int key)
//得到單鏈表的長度
public int size()
public void show()
public void clear()
}
class
node
}public
class
doublelinkedlist
else
}public
void
addlast
(int val)
else
}public
boolean
contain
(int key)
cur = cur.next;
}return
false;}
public
void
show()
system.out.
println()
;}public
intsize()
return count;
}public node searchindex
(int index)
int count =0;
while
(index !=0)
return cur;
}public
void
addindex
(int index,
int val)
else
if(index ==0)
else
if(index ==
size()
)else
}public
void
remove
(int key)
else
else
}return;}
cur = cur.next;}}
public
void
removeall
(int key)
this
.head =
this
.head.next;
//刪除頭節點
無頭雙向鍊錶
class node public class mylinkedlist else 尾插法 public void addlast int data else private void checkindex int index private node searchindex int index r...
無頭結點鍊錶
include include linklist.h struct node create linklist creat linklist 根據使用者輸入,建立乙個單鏈表 struct node pnew struct node malloc sizeof struct node pnew data...
無頭單向不迴圈鍊錶和帶頭雙向迴圈鍊錶
無頭單向不迴圈鍊錶 include include slist.h typedef int sltdatetype typedef struct slistnode slistnode 動態申請乙個節點 slistnode buyslistnode sltdatetype x 單鏈表列印 void ...