当前位置:网站首页>go language study notes 4
go language study notes 4
2022-07-30 05:02:00 【N. LAWLIET】
Definition of go language structure
type student struct{name stringage int}The structure of the go language is an object-oriented method, there is no this pointer, no method override and no extends
The structure is passed by value, and the copy is also a shallow copy.
The structure can implement a variety of data structures, which can be used as a list
For example
type node struct{val stringnext *node}queue, stack, tree, etc. can be implemented with structures.
The structure pointer is named as follows
list := new(node)//Life structure method one(*list).val = "123"(*list).next = &new(node)fmt.println((*list))list2 := &(node("456",&new(node)))fmt.println(list2)The structure also has the attribute of slice mapping, and the address is the address of the first field
Algorithm title: How to restore a binary tree according to the preorder traversal of the search binary tree
package mainimport ("fmt")var array[10000]inttype bt struct {val intleft *btright *bt}var index int = 0func preOrder(root *bt) [10000]int {if root != nil {array[index] = root.valindex += 1preOrder(root.left)preOrder(root.right)}return array}func treeMain() {var root btroot.val = 10var left btvar right btleft.val = 5right.val = 15root.left = &leftroot.right = &rightvar arr[10000]int = preOrder(&root)var ans bt = reTree(&arr)fmt.Println(ans.left.val)}func reTree(preArr *[10000]int) bt {if len(preArr) <= 0 {var nilBoot btreturn nilBoot}var root btprocess1(preArr, 0, 1, 2, &root)return root}func process1(arrays *[10000]int, index int, L int, R int, ansTree *bt) {if L > len(array)-1 || R > len(array)-1 {return}ansTree.val = arrays[index]if arrays[L] < arrays[index] {var left btansTree.left = &leftprocess1(arrays, L, L+1, R, &left)}if arrays[R] > arrays[index] {var right btansTree.right = &rightprocess1(arrays, R, L, R+1, &right)}}边栏推荐
- go语言学习笔记三
- POJ1321 chessboard problem (detailed explanation)
- Discourse 自定义头部链接(Custom Header Links)
- 需求设计文档和产品经理的角色改变
- Detailed explanation of REUSE_ALV_GRID_DISPLAY
- How with Mexico Volkswagen VW EDI connection to Mexico
- 2.5 Quick Sort
- Unity beginner 5 cameras follow, border control and simple particle control (2 d)
- mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
- 22. 为什么需要消息队列?使用消息队列有什么好处?
猜你喜欢

Usage of EFR32 as sniffer for Zigbee/Thread

Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction

ms project2010项目管理软件使用技巧总结

Classification of decision tree classification

5. View parsing and template engine

3. Dependency configuration management

Recursive Optimization of Fibonacci Sequences "Memo Recursion"

Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds

Stimulsoft ReportsJS and DashboardsJS. 2022.3.3

1. Get data - requests.get()
随机推荐
Go study notes (84) - Go project directory structure
Code readability, pre-checks, comments and summaries
Double pointer problem (middle)
SVN 查看用户名密码
Simulation problem (middle)
Chapter8 Support Vector Machines
Solve the go environment can not compile exe
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
Boss Rush (two-point answer + DP)
Simulation Problem (Part 1)
The VUX Datetime component compute-days-function dynamically sets the date list
小程序npm包--API Promise化
五、视图解析与模板引擎
C. Qualification Rounds
Usage of EFR32 as sniffer for Zigbee/Thread
String Problem (Part 1)
Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem
Naive Bayes Classification
BindingExpression path error: 'selectMenusList' property not found on 'object' ''ViewModel'
Golang channel implementation principle