当前位置:网站首页>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)}}边栏推荐
- C. Qualification Rounds
- 模拟问题(中)
- 1. Get data - requests.get()
- WPF introduces ttf icon file usage record
- 2.6 Radix sort (bucket sort)
- Go study notes (84) - Go project directory structure
- 四、Web开发
- The VUX Datetime component compute-days-function dynamically sets the date list
- The Azure developer news 丨 memorabilia in July
- Unity beginner 5 cameras follow, border control and simple particle control (2 d)
猜你喜欢

uni-app realizes cross-end development of mobile phone Bluetooth to receive and send data

Code open source design and implementation ideas

模拟问题(中)

Protobuf compound data types, speaking, reading and writing

GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13

Hexagon_V65_Programmers_Reference_Manual(12)

2.6 Radix sort (bucket sort)

Hexagon_V65_Programmers_Reference_Manual (14)

DAY17, CSRF vulnerability

Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
随机推荐
go语言学习笔记二
Simulation problem (middle)
SVN 查看用户名密码
Verify that the addShutdownHook hook takes effect
Learning of redis_Basic part
DAY17: weak password detection and test
BindingExpression path error: 'selectMenusList' property not found on 'object' ''ViewModel'
POJ1321 棋盘问题(详解)
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
1315_使用LOOPBACK模拟模式pyserial安装是否成功的测试
Catch That Cow (detailed)
VisualStudio2022本地调试进入特别慢问题解决
SaaS多租户数据隔离的三种解决方案
String problem (below)
How with Mexico Volkswagen VW EDI connection to Mexico
C# One Week Introductory "C# - Classes and Objects" Day Six
Intermediate - interview questions
LeetCode Algorithm 2326. Spiral Matrix IV
1. Get data - requests.get()
模拟问题(中)