Coursera C++ Part A [Week2] Class and Generics

Coursera C++ Part A [Week1] https://www.jianshu.com/p/6c1d07763275

Week1了解了C++和C的基本区别, Week2开始介绍类

week2 Overview

C++ functions and generics
Review Dijkstra's shortest path algorithm
C++ classes and OO
Point as an example

C中数组的两种表示方法: type array_name[], type* array_name

C++ functions and generics

    template // T is generic type
    T function(T data)

Review Dijkstra's shortest path algorithm

    图的数据结构:
    稠密图:临接矩阵 
    稀疏图:临接表   1->2->5....

    Dijkstra shortest path algorithm:   from s to d
        1. 将出发点s放入闭合集,所有和s直接相邻的点放入开放集
        2. 在开放集中选择cost最小的点v放入闭合集
        3. 用v的直接临界点扩充开放集,并用较小的值更新开放集中各个点的cost。选取开放集中cost最小的点放入闭合集
        4. 直到d进入闭合集 迭代结束

C++ classes and OO

enum: typedef enum color{RED, BLUE, GREEN} color; where red is defaulted to 0, BLUE is 1, GREEN is 2.

class class_name{public:; private:; protected;}
类的成员函数会自动inline,效率有所提高

你可能感兴趣的:(Coursera C++ Part A [Week2] Class and Generics)