網(wǎng)站首頁 編程語言 正文
Golang的列表元素的獲取可以使用內(nèi)置的 Front 函數(shù)獲取頭結(jié)點,使用 Back 函數(shù)獲取尾結(jié)點,使用 Prev 獲取前一個結(jié)點,使用 Next 獲取下一個結(jié)點。
1、獲取列表頭結(jié)點
Front() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Front() 函數(shù),獲取列表的頭結(jié)點 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é)點。
2、獲取列表尾結(jié)點
Back () *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Back() 函數(shù),獲取列表的尾結(jié)點 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é)點。
3、獲取上一個結(jié)點
Prev() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Prev() 函數(shù),獲取列表的上一個結(jié)點 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ù),獲取列表的上一個結(jié)點。
4、獲取下一個結(jié)點
Next() *Element
package main import ( "container/list" "fmt" ) func main() { fmt.Println("嗨客網(wǎng)(www.haicoder.net)") //使用列表內(nèi)置的 Next() 函數(shù),獲取列表的下一個結(jié)點 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ù),獲取列表的下一個結(jié)點。
原文鏈接:https://blog.csdn.net/qq_19734597/article/details/121097335
相關(guān)推薦
- 2022-08-15 springboot的熱部署配置
- 2022-09-29 Python?pkg_resources模塊動態(tài)加載插件實例分析_python
- 2022-09-25 nginx平滑升級、nginx支持的kill信號
- 2023-07-04 maven引入本地jar,打包問題
- 2022-03-29 PostgreSQL13基于流復(fù)制搭建后備服務(wù)器的方法_PostgreSQL
- 2022-03-15 org.springframework.web.client.RestTemplate 上傳文件無法
- 2022-04-27 幾個關(guān)于python??Pdf?技巧的分享_python
- 2022-05-22 Nginx設(shè)置HTTPS的方法步驟_nginx
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 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錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支