当前位置:网站首页>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)}}
边栏推荐
- Code open source design and implementation ideas
- 动态规划问题(完结篇)
- 双指针问题(中)
- webService接口
- 解决go环境编译不了exe
- String Problem (Part 1)
- [C language] Program environment and preprocessing
- WPF recursively obtains the list of specified control types in the form
- 七、自定义配置
- [Android development] Splash interface / user agreement and privacy policy pop-up window / interface development
猜你喜欢
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
动态规划问题(完结篇)
Acwing完全数
【Vitis】ZCU102开发板PS端控制PL端复位的代码实现
Plan for many situations in the processing chain
IGBT wafers used in photovoltaic inverters
Repetition XXL - JOB scheduling center background arbitrary command execution
Using the GPU parallel computing 】 【 OpenCL&OpenCLUtilty GPU parallel computing
小程序npm包--API Promise化
WPF introduces ttf icon file usage record
随机推荐
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
2.5 Quick Sort
go语言学习笔记二
The Azure developer news 丨 memorabilia in July
mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
Simulation problem (below)
Predictive maintenance scheduling of multiple power equipment based on data-driven fault prediction
QT(39)-vs development qt program prompts that the source file cannot be opened
Hexagon_V65_Programmers_Reference_Manual(12)
Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview
Image stitching (registration) case based on OpenCV
webService接口
全流程调度——Azkaban入门与进阶
[High Performance Computing] openMP
Golang eight-legged text finishing (continuous handling)
动态规划问题(完结篇)
斐波那契数列的递归优化《备忘录递归》
DAY17: weak password detection and test
Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction
如何与墨西哥大众VW Mexico建立EDI连接