無頭雙向鍊錶

2021-10-05 16:46:39 字數 1445 閱讀 4397

class

node

}public

class

mylinkedlist

else

}//尾插法

public

void

addlast

(int data)

else

}private

void

checkindex

(int index)

}private node searchindex

(int index)

return cur;

}//任意位置插入,第乙個資料節點為0號下標

public

void

addindex

(int index,

int data)

if(index ==

size()

) node cur =

searchindex

(index)

; node node =

newnode

(data)

; 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

intremove

(int key)

else

else

}return olddata;

} cur = cur.next;

}return-1

;}//刪除所有值為key的節點

public

void

removeallkey

(int key)

}else

else}}

cur = cur.next;}}

//得到單鏈表的長度

public

intsize()

return count;

}//列印鍊錶

public

void

display()

system.out.

println()

;}/** * 乙個乙個節點進行釋放了

*/public

void

clear()

this

.tail = null;

}}

無頭雙向鍊錶方法

public class doublelinkedlist 尾插法 public void addlast int data 任意位置插入,第乙個資料節點為0號下標 public boolean addindex int index,int data 查詢是否包含關鍵字key是否在單鏈表當中 pub...

無頭結點鍊錶

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 ...