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 Golang
a subset of the language, enough to carry out the next data structure and algorithm implementation.
I. Introduction
Golang
The language is a high-level programming language that Google
was launched by Google in 2007 and officially released in 2009 开源
. Open source address: https://github.com/golang/go , official website address: https://golang.org .
Golang
The 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/JavaScript
other high-level programming languages.
The designers who designed this language have the following:
Ken Thompson
: At Bell Labs,Dennis M. Ritche
invented theC
language andUnix
operating system, andRob Pike
invented theUTF-8
coding, the Turing Award winner.Rob Pike
: Also participated in the development of theUnix
operating system,UTF-8
one of the inventors of the encoding.Robert Griesemer
: Participated in the development ofV8 JavaScript
engines andJava HotSpot
virtual 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 msi
to install according to the prompt, Mac operating system can be used to brew install golang
install.
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 Golang
suffix 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: main
or 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:
- What are supported
基本数据类型
, such as integers, floating-point numbers, Boolean values, strings, and which advanced data types are supported, such as arrays, structures, etc. if
Determinewhile
what the loop statement is and whether there areswitch
orgoto
wait statements.函数
What is the definition of language , how to pass function parameters, whether there are any面向对象
language features, etc.package
What 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.- 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 .
- Data structure and algorithm (Golang implementation) (1) A simple introduction to Golang-Preface
- Data structures and algorithms (Golang implementation) (2) A simple introduction to Golang-packages, variables and functions
- Data structure and algorithm (Golang implementation) (3) A simple introduction to Golang-flow control statement
- Data structures and algorithms (Golang implementation) (4) A simple introduction to Golang-structures and methods
- Data structure and algorithm (Golang implementation) (5) A simple introduction to Golang-interface
- Data structure and algorithm (Golang implementation) (6) A simple introduction to Golang-concurrency, coroutines and channels
- Data structure and algorithm (Golang implementation) (7) A simple introduction to Golang-standard library
- Data Structure and Algorithm (Golang Implementation) (8.1) Basic Knowledge-Preface
- Data Structure and Algorithm (Golang Implementation) (8.2) Basic Knowledge-Divide and Conquer and Recursion
- Data structure and algorithm (Golang implementation) (9) Basic knowledge-algorithm complexity and progressive symbol
- Data structure and algorithm (Golang implementation) (10) Basic knowledge-the main method of algorithm complexity
- Data Structures and Algorithms (Golang Implementation) (11) Common Data Structures-Preface
- Data structures and algorithms (Golang implementation) (12) Common data structures-linked lists
- Data structures and algorithms (Golang implementation) (13) Common data structures-variable-length arrays
- Data structures and algorithms (Golang implementation) (14) Common data structures-stack and queue
- Data Structures and Algorithms (Golang Implementation) (15) Common Data Structures-List
- Data Structures and Algorithms (Golang Implementation) (16) Common Data Structures-Dictionary
- Data structures and algorithms (Golang implementation) (17) Common data structures-trees
- Data Structure and Algorithm (Golang Implementation) (18) Sorting Algorithm-Preface
- Data structure and algorithm (Golang implementation) (19) Sorting algorithm-bubble sorting
- Data structure and algorithm (Golang implementation) (20) Sorting algorithm-selection sorting
- Data structure and algorithm (Golang implementation) (21) Sorting algorithm-insertion sort
- Data structure and algorithm (Golang implementation) (22) Sorting algorithm-Hill sorting
- Data structure and algorithm (Golang implementation) (23) Sorting algorithm-merge sorting
- Data structure and algorithm (Golang implementation) (24) Sorting algorithm-priority queue and heap sorting
- Data structure and algorithm (Golang implementation) (25) Sorting algorithm-quick sorting
- Data Structure and Algorithm (Golang Implementation) (26) Lookup Algorithm-Hash Table
- Data structure and algorithm (Golang implementation) (27) Search algorithm-binary search tree
- Data structure and algorithm (Golang implementation) (28) Search algorithm-AVL tree
- Data structure and algorithm (Golang implementation) (29) Finding algorithm-2-3 tree and left-leaning red-black tree
- Data structure and algorithm (implemented by Golang) (30) Finding algorithm-2-3-4 tree and ordinary red-black tree