資料結構之單鏈表No 5

2021-10-05 11:21:01 字數 1328 閱讀 4028

package main

import (

"fmt"

)//定義乙個 heronode

type heronode struct

//給鍊錶插入乙個結點 根據 no 的編號從小到大插入..【實用】

func insertheronode(head *heronode, newheronode *heronode) else if temp.next.no > newheronode.no else if temp.next.no == newheronode.no

temp = temp.next

} if !flag else

}//刪除節點

func deleteheronode(head *heronode, id int) else if temp.next.no == id

temp = temp.next

} if temp.next == nil else

}//修改節點

func updateheronode(head *heronode, newheronode *heronode) else if temp.next.no == newheronode.no

temp = temp.next

} if temp.next == nil else

}//顯示鍊錶的所有結點資訊

func listheronode(head *heronode)

//2. 遍歷這個鍊錶

for }}

func main()

//2. 建立乙個新的 heronode

hero1 := &heronode

hero2 := &heronode

hero3 := &heronode

//3. 加入

insertheronode(head, hero3)

insertheronode(head, hero1)

insertheronode(head, hero2)

listheronode(head)

fmt.println("")

//刪除列表

deleteheronode(head,3)

listheronode(head)

fmt.println("")

//修改列表

uphero2 := &heronode

updateheronode(head,uphero2)

// 4. 顯示

listheronode(head)

fmt.println("")

}

我的大學之資料結構NO 5

哈夫曼編碼 一 需求分析 從終端讀入字符集大小n,依次輸入n個字元和相應的權值,建立哈夫曼樹。輸入一串電文,程式顯示出電文翻譯的位元流,在輸入一串位元流,程式顯示位元流翻譯的電文。二 部分 1.建立結構體 typedef structhtelemtype typedef structhtree st...

資料結構之單鏈表

date 08 07 06 descript 單鏈表的實現與應用 public class linlist public node gethead 定位函式 public void index int i throws exception if i 1 current head.next int j...

資料結構之單鏈表

鍊錶 儲存結構的一種,包含兩個部分,資料域和指標域,相對於順序儲存結構來說,插入和刪除的演算法時間複雜度只為o 1 定義 定義 typedef struct node linklist linklist,指標指向每乙個元素 typedef struct nodenode 以下為簡單的c語言實現 in...