Data structure and algorithm (Golang implementation) (1) A simple introduction to Golang-Preface

Data structures and algorithms have a very important position in computer science. This series of articles attempts to use the Golang programming language to implement various data structures and algorithms, and analyze algorithms appropriately.

We will first briefly learn about Golang, and then enter the first door of the world of computer programs.

A simple introduction to Golang

We only learn Golanga subset of the language, enough to carry out the next data structure and algorithm implementation.

I. Introduction

GolangThe language is a high-level programming language that Googlewas launched by Google in 2007 and officially released in 2009 开源. Open source address: https://github.com/golang/go , official website address: https://golang.org .

GolangThe language syntax is simple, supports multi-platform cross-compilation (Linux / Mac / Windows), supports automatic memory GC(garbage collection), supports embedded C/C++development, and implements thread scheduling at the syntax level, developing multi-threaded programs is very convenient. The syntax is very much like C/Python/JavaScriptother high-level programming languages.

The designers who designed this language have the following:

  1. Ken Thompson: At Bell Labs, Dennis M. Ritcheinvented the Clanguage and Unixoperating system, and Rob Pikeinvented the UTF-8coding, the Turing Award winner.
  2. Rob Pike: Also participated in the development of the Unixoperating system, UTF-8one of the inventors of the encoding.
  3. Robert Griesemer: Participated in the development of V8 JavaScriptengines and Java HotSpotvirtual machines.

The first two are relatively well-known, and are now retired, others can Google if they are interested.

2. Installation and simple use

Install Golang: https://golang.org/dl: Windows operating system Click msito install according to the prompt, Mac operating system can be used to brew install golanginstall.

Open a command line terminal and enter:

go version

The following results are displayed as success:

go version go1.13 darwin/amd64

Create a new file in any folder main.go(the Golangsuffix of program files written in language must be all .go):

package main

import (
    "fmt"
    "time"
)

func init() {
    fmt.Println("init will be before hello world")
}

func main() {
    fmt.Println("hello world")
    fmt.Println("today times:" + time.Now().String())
}

Open the command line terminal to compile:

go build main.go

After compilation, a binary file will be generated in the local folder: mainor main.exe(Windows system).

Perform binary:

./main

The following result will be printed:

init will be before hello world
hello world
today times:2019-12-09 13:14:14.383118 +0800 CST m=+0.000199077

3. How to learn a language

Every learning of a programming language is inseparable from learning its language features:

  1. What are supported 基本数据类型, such as integers, floating-point numbers, Boolean values, strings, and which advanced data types are supported, such as arrays, structures, etc.
  2. ifDetermine whilewhat the loop statement is and whether there are switchor gotowait statements.
  3. 函数What is the definition of language , how to pass function parameters, whether there are any 面向对象language features, etc.
  4. packageWhat is package management, how to manage a project, what standard libraries does the official provide, such as time processing, string processing, HTTP library, encryption library, etc.
  5. Are there any special language features that are not available in other languages, such as certain syntactic sugar.

Series article entry

I am the star Chen, Welcome I have personally written data structures and algorithms (Golang achieve) , starting in the article to read more friendly GitBook .

Published 13 original articles · Likes0 · Visits 98

Guess you like

Origin blog.csdn.net/m0_46803965/article/details/105563142