package
com.tyxh.link;
//節點類
public
class
node
//顯示此節點
public
void
display()
} package
com.tyxh.link;
//單鏈表
public
class
linklist
// 插入乙個頭節點
public
void
addfirstnode(
intdata)
// 刪除乙個頭結點,並返回頭結點
public
node deletefirstnode()
// 在任意位置插入節點 在index的前面插入
public
void
add(
intindex,
intdata)
node. next = current;
previous. next = node;
pos = 0
; }
// 刪除任意位置的節點
public
node deletebypos(
intindex)
if(current == first) else
return
current;
} // 根據節點的data刪除節點(僅僅刪除第乙個)
public
node deletebydata(
intdata)
previous = current;
current = current. next;
} if
(current == first) else
return
current;
} // 顯示出所有的節點資訊
public
void
displayallnodes()
system. out.println();
} // 根據位置查詢節點資訊
public
node findbypos(
intindex)
return
current;
} // 根據資料查詢節點資訊
public
node findbydata(
intdata)
return
current;
} }
package
com.tyxh.link;
//測試類
public
class
testlinklist
}
單鏈表基本操作java實現
閒來無事,寫個資料結構鍊錶的實現 如下 package com.data structs class link class linklist 在表頭插入新的資料 public void insertfirst e value 判斷鍊錶是否為空 public boolean isempty 刪除表頭 ...
JAVA實現單鏈表的基本操作
複習單鏈表的實現,紮實基礎,單鏈表的結構不在贅述,直接看 注釋的很清楚 注意 在插入和刪除操作時,需要判斷是否越界,如何判斷上界?想到了在修改.public class linklist node head null 煉表頭的引用初始化為空 尾插 public void addnode int a ...
單鏈表基本操作的實現
package pac1 class node public void show public class linklist 插入乙個頭結點 public void addheadnode int data 頭插法建立表,將新節點插入到頭結點之後 public void creatlist1 lin...