This is a creation in Article, where the information may have evolved or changed.
Go programming Language: Support concurrent, garbage collection of compiled system-level programming language! This paper is mainly based on the "Go Programming Basics" Open source video to learn and record notes.
An array of arrays
- To define the format of an array:
var<varName>[n]<type> (n>=0, n表示数组元素个数)
数组长度也是类型的一部分, so arrays with different lengths are of different types
- Note
指向数组的指针 the distinction and指针数组
- Array is a value type in Go
- You can use = = or! = to compare between arrays, but you cannot use < or >
- You can use
new to create an array, which returns a pointer to an array
- Go supports multidimensional arrays
Example:
package mainimport "fmt" func main() { // var a [2]int a := [2]int{1,2} fmt.Println(a)}
Printing results:
[1 2]
New Create Data
// var a [2]int a := [10]int{} a[1] = 2 fmt.Println(a) p := new([10]int) p[1] = 2 fmt.Println(p)
Printing results:
➜ run arr.go[0 2 0 0 0 0 0 0 0 0]&[0 2 0 0 0 0 0 0 0 0]
Look, what's the difference between the top? The second line results with an address character&
Multidimensional arrays
a := [2][3]int{ {1, 2, 3}, {4, 5, 6}} fmt.Println(a)
Printing results:
[[1 2 3] [4 5 6]]
Bubble Sort Method:
Package Mainimport "FMT"//Bubble sort func main () {//... can represent an indeterminate number of elements a: = [...] Int{1, 4, 9, 2, 5, 0, A, a, 3} fmt. Println (a)//calculates the length of the array num: = Len (a) for I: = 0; i < num; i++ {///outer loop, once per loop, will rank the maximum value in front for j: = i + 1; j < num; J + + {if a[i] < A[j] {Temp : = A[i] a[i] = a[j] a[j] = temp}}} fmt. Println (A)}