鍊錶的java實現和常用操作實現方法

2021-08-09 09:36:32 字數 694 閱讀 1594

注意,鍊錶要有head;

public class mylist 

} /**

* 鍊錶尾部插入節點

*/public void add(int d)

node tmp = head;

while(tmp.next != null)

tmp.next = node;

} /**

* 鍊錶刪除第index節點(從1開始)

*/public boolean delete(int index)

if(index == 1)

int i=1;

node pre = head;

node cur = head.next;

while(cur!=null)

pre = cur;

cur = cur.next;

i++;

} return false;

} /**

* 返回節點長度

*/private int length()

return length;

} /**

* 在不知道頭指標的情況下刪除指定節點,該節點為尾節點時返回false【有點問題!】

*/public boolean delete(node n) else

}}

java實現鍊錶操作

package com.fsc.mylinkedlist 線性表操作介面 author fsc param public inte ce listinte ce 為了插入和刪除 的一致性,引入了哨兵節點 也就是下面 中出現的firstnode 下標的選擇和陣列的規則相同,都是從0開始。為了滿足下標的...

順序表和煉表的基本操作(Java實現)

線性表 頭插 尾插 中間插入 頭刪 尾刪 1.順序表 想細節,寫偽 難點 迴圈邊界 2.鍊錶 結點和結點之間的邏輯關係 邏輯上有前後關係,物理儲存也是前後相連的。頭插 思考 偽 1.需要後移size個元素 2.為避免資料被覆蓋,從後往前移 3.空間 size,1 資料 size 1,0 4.arra...

鍊錶常用操作 C 實現

一 標頭檔案,每個結點包括資料和指標 pragma once include struct node class linlist 二 在cpp檔案中重新定義基本操作函式 include stdafx.h include linlist.h using namespace std linlist li...