当前位置:网站首页>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)}}边栏推荐
- 2.5 Quick Sort
- POJ1321 棋盘问题(详解)
- pyinstaller打包程序所遇问题记录
- 复现XXL-JOB 任务调度中心后台任意命令执行漏洞
- 【Vitis】ZCU102开发板PS端控制PL端复位的代码实现
- The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
- 双指针问题(下)
- GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
- POJ1321 chessboard problem (detailed explanation)
- 斐波那契数列的递归优化《备忘录递归》
猜你喜欢

Dynamic Programming Problems (End)
Go study notes (84) - Go project directory structure

Simple experiment with BGP

Simulation problem (middle)

Acwing完全数

A must see for software testers!Database knowledge MySQL query statement Daquan

Shanxi group (enterprises) in the second network security skills competition part problem WP (7)

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

QT(39)-vs development qt program prompts that the source file cannot be opened
![[Vitis] Code implementation of ZCU102 development board PS-side control PL-side reset](/img/f2/429e3dd157647bb614595a83843140.png)
[Vitis] Code implementation of ZCU102 development board PS-side control PL-side reset
随机推荐
L2-025 分而治之
Image stitching (registration) case based on OpenCV
五、视图解析与模板引擎
Shanxi group (enterprises) in the second network security skills competition part problem WP (8)
DAY17, CSRF vulnerability
SaaS多租户数据隔离的三种解决方案
"Translation" Envoy Fundamentals, this is a training course, make people to more quickly using Envoy Proxy..
Whole process scheduling - Azkaban entry and advanced
【Verilog】HDLBits题解——Circuits/Combinational Logic
The Azure developer news 丨 memorabilia in July
Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
Small programs use npm packages to customize global styles
Detailed explanation of REUSE_ALV_GRID_DISPLAY
Plan for many situations in the processing chain
go language study notes 2
需求设计文档和产品经理的角色改变
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
Shi Xingguo, founder of Hyperchain, was interviewed by 21st Century Business Herald to interpret Shanghai's new NFT regulations and digital development
Simulation problem (middle)
LeetCode Algorithm 2326. 螺旋矩阵 IV