Go Basic Learning Three

Source: Internet
Author: User
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)}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.