Java鍊錶(基本操作)

2021-08-15 03:15:36 字數 397 閱讀 2749

·鍊錶是一種最為簡單的資料結構,它的主要目的是依靠引用關係來實現多個資料的儲存,下面**以string字串型別示例

class node 

public void setnext(node next)

public node getnext()

public string getdata()

}public class nodetest

// 列印方法採取遞迴呼叫

public static void print(node current)

system.out.println(current.getdata());

print(current.getnext());

}}

java鍊錶基本操作

主要通過編碼實現單鏈表的基礎操作 1 從頭插入節點 2 插入鍊錶中指定位置的節點 3 根據指定的value來查詢節點 4 根據指定的節點索引來查詢節點 5 刪除第乙個節點 6 刪除節點指定位置的值 7 刪除指定索引的節點 8 列印列表資訊 public class node 顯示資料 public ...

鍊錶基本操作

include include string h include typedef struct stust void xj st h 生成單鏈表 l l null void shc st h 輸出鍊錶 printf d n h d void chr st h 按大小插入元素 else h h l v...

鍊錶基本操作

動態記憶體的相關知識int p null 定義指標變數 p int malloc sizeof int 申請記憶體空間,並且進行強制型別轉換 p 3 使用指標變數 typedef struct list typedef struct listnode listpointer struct listn...