boost meta state machine

MSM Meta State Machine,是boost库的元状态机,使用了大量的模板元编程,让使用者轻松创建出好用,可阅读,效率高的状态机。它的特点是使用状态转

Hugo and git submodule

介绍 hugo + gitee搭建个人博客,使用gitee代替github是因为国内访问速度问题。 hugo直接在仓库可以安装sudo apt install hugo,这个链

二叉树的非递归遍历

二叉树的遍历有前序,中序,后序以及层次遍历,其中前序,中序和后序遍历使用递归来写非常简单。
例如

1
2
3
4
5
6
7
void tree_preorder_re(TreeNode *node, Tree *tree, void (*visit)(Tree *, TreeNode *))
{
    if (!node) return;
    visit(tree, node);
    tree_preorder_re(node->left, tree, visit);
    tree_preorder_re(node->right, tree, visit);
}

中序和后序,不过是调整一下visit的位置,如果不用递归的写法,改用栈来实现,其实没有那么直观。
首先按照函数调用的关系,入栈的套路都是一样的。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    Stack *s = stack_new();
    TreeNode *tNode = tree->root;
    while (stack_depth(s) != 0 || tNode)
    {
        while (tNode != NULL)
        {
            stack_push(s, tNode);
            tNode = tNode->left;
        }

        if (!stack_is_empty(s))
        {
            tNode = (TreeNode *)stack_pop(s);
            tNode = tNode->right;
        }
    }

    stack_free(s);

使用grub创建多系统u盘安装盘

现在装系统都是用u盘安装了,一个u盘只能安装一个系统有些浪费了,因为空间足够大,可以装下好几个iso文件。
在linux环境中,使用dd命令只能制作一个引导盘,且其他空间不能再使用。从网上看用YUMI可以比较方便的制作多系统引导。然而实测发现是linux系统上实在太难用,装WINE也用不了。后来看到grub的方法成功实现了。

右值引用

右值引用

  • 使用&&表示
  • 只能绑定到一个将要销毁的对象
  • 左值持久,右值短暂
  • 将左值转换为对应的右值使用std::move