網(wǎng)站首頁 編程語言 正文
Golang的列表元素的獲取可以使用內(nèi)置的 Front 函數(shù)獲取頭結(jié)點(diǎn),使用 Back 函數(shù)獲取尾結(jié)點(diǎn),使用 Prev 獲取前一個(gè)結(jié)點(diǎn),使用 Next 獲取下一個(gè)結(jié)點(diǎn)。
1、獲取列表頭結(jié)點(diǎn)
Front() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Front() 函數(shù),獲取列表的頭結(jié)點(diǎn) listHaiCoder := list.New() listHaiCoder.PushFront("Hello") listHaiCoder.PushFront("HaiCoder") listHaiCoder.PushFront("嗨客網(wǎng)") element := listHaiCoder.Front() fmt.Println("Front =", element.Value) }
使用列表內(nèi)置的 Front() 函數(shù),獲取列表的頭結(jié)點(diǎn)。
2、獲取列表尾結(jié)點(diǎn)
Back () *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Back() 函數(shù),獲取列表的尾結(jié)點(diǎn) listHaiCoder := list.New() listHaiCoder.PushFront("Hello") listHaiCoder.PushFront("HaiCoder") listHaiCoder.PushFront("嗨客網(wǎng)") element := listHaiCoder.Back() fmt.Println("Back =", element.Value) }
使用列表內(nèi)置的 Back() 函數(shù),獲取列表的尾結(jié)點(diǎn)。
3、獲取上一個(gè)結(jié)點(diǎn)
Prev() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Prev() 函數(shù),獲取列表的上一個(gè)結(jié)點(diǎn) listHaiCoder := list.New() listHaiCoder.PushFront("Hello") element := listHaiCoder.PushFront("HaiCoder") listHaiCoder.PushFront("嗨客網(wǎng)") preElement := element.Prev() fmt.Println("preElement =", preElement.Value) }
使用列表內(nèi)置的 Prev() 函數(shù),獲取列表的上一個(gè)結(jié)點(diǎn)。
4、獲取下一個(gè)結(jié)點(diǎn)
Next() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Next() 函數(shù),獲取列表的下一個(gè)結(jié)點(diǎn) listHaiCoder := list.New() listHaiCoder.PushFront("Hello") element := listHaiCoder.PushFront("HaiCoder") listHaiCoder.PushFront("嗨客網(wǎng)") nextElement := element.Next() fmt.Println("nextElement =", nextElement.Value) }
使用列表內(nèi)置的 Next() 函數(shù),獲取列表的下一個(gè)結(jié)點(diǎn)。
原文鏈接:https://blog.csdn.net/qq_19734597/article/details/121097335
相關(guān)推薦
- 2022-11-04 React組件化學(xué)習(xí)入門教程講解_React
- 2022-12-22 數(shù)據(jù)清洗之如何用一行Python代碼去掉文本中的各種符號(hào)_python
- 2022-12-13 Dart多態(tài)控制反轉(zhuǎn)編碼規(guī)范實(shí)例詳解_Dart
- 2022-08-15 數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組棧的實(shí)現(xiàn)
- 2023-06-13 react拖拽組件react-sortable-hoc的使用_React
- 2022-12-10 K8S節(jié)點(diǎn)本地存儲(chǔ)被撐爆問題徹底解決方法_云其它
- 2022-10-12 Nginx?504?Gateway?Time-out的兩種最新解決方案_nginx
- 2022-02-20 Unity3D實(shí)現(xiàn)經(jīng)典小游戲Pacman_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支