鍊錶 有序鍊錶(插入刪除遍歷)

2022-06-10 01:54:10 字數 743 閱讀 5680

插入的節點位置有兩種情況,一是有previous節點,而是沒有previous節點

//

鏈結點public

class

link

public

void

displaylink()

}

public

class

sortedlist

//插入資料

public

void insert(long

key)

//說明key是最小值

if(previous==null

) first=newlink;//

改變first即可

else

previous.next=newlink;//

不為空,與左側需要連線

newlink.next=current;//

就算key是最大值,current會是null,這樣也成立

}

//從first端刪除

public

link remove()

//遍歷

public

void

display()

system.out.println();

}}

public

class

test

}

鍊錶插入刪除

include include typedef struct node node,linklist void createlist linklist head 建立鍊錶 s node malloc sizeof node s next null s data data p next s p s in...

單向鍊錶 建立 插入 刪除 遍歷

include include include using namespace std struct list create 新建鍊錶 struct list insert struct list head,struct list temp 插入 struct list deletes struct...

鍊錶的建立,插入,刪除,遍歷

includeusing namespace std define ok 1 define error 0 define overflow 2 typedef int status status 是函式返回值型別,其值是函式結果狀態 typedef int elemtype elemtype 為可定...