C++protobuf基础


简介

protobuf也叫protocol buffer是google 的一种数据交换的格式,它独立于语言,独立于平台。google 提供了多种语言的实现:java、c#、c++、go 和 python 等,每一种实现都包含了相应语言的编译器以及库文件。 由于它是一种二进制的格式,比使用 xml 、json进行数据交换快许多。可以把它用于分布式应用之间的数据通信或者异构环境下的数据交换。作为一种效率和兼容性都很优秀的二进制数据传输格式,可以用于诸如网络传输、配置文件、数据存储等诸多领域。

安装

# 下载
wget https://github.com/protocolbuffers/...

Read more

C网络编程(一)


操作系统Ubuntu 22.04 编译器gcc-11

server.c

//
// Created by ZJ on 2023/11/20.
//
#include <arpa/inet.h> // linux中ip地址port端口类型转换库 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h> // linux socket 相关函数库
#include <unistd.h> // read wri...

Read more

常见排序算法


Python版本

def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr

def insertion_sort(arr):
    n = len(arr)
    for i in range(1, n):
       key = arr[i]...

Read more

C++ STL之自制map


#include <cassert>
#include <iostream>
#include <string>

template <typename K, typename V>
class Map
{
private:
    class KeyValuePair
    {
    public:
        KeyValuePair(K k, V v) : key(k), value(v), next(nullptr) {}
        K key;
        V value;
        KeyValuePai...

Read more

ubuntu下编译安装vim最新版


# 克隆vim源码
git clone https://github.com/vim/vim.git
cd vim

./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-python3interp=yes \
--with-python3-config-dir=/usr/lib/python3.10/config-3.10-x86_64-linux-gnu \
--enable-perlinterp=yes \
--enable-luainterp=yes...

Read more

C++STL之Map基础使用


#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<int, string> m1;
    m1.insert(pair<int, string>(1, "one"));
    m1.insert(pair<int, string>(2, "two"));
    m1.insert(pair<int, string>(3, "three"));
 ...

Read more

C++STL之自制vector


#include <algorithm>
#include <iostream>
#include <assert.h>

using namespace std;
#define WALK_LENGTH 64;

template <typename T>
class myVector
{
private:
    T *array;
    unsigned int theSize;
    unsigned int theCapacity;

    T *allocator(unsigned int size)
    {
    ...

Read more

C非递归遍历二叉树


#include <stdio.h>
#include <stdlib.h>

#define True 1
#define False 0
typedef char bool;

typedef struct TreeNode
{
    char data;
    struct TreeNode *left;
    struct TreeNode *right;
    unsigned int flag;
} TreeNode;

typedef struct StackNode
{
    TreeNode *data;
    struct Stac...

Read more

C二叉树创建与遍历


C二叉树创建与遍历

image-20231216152139390

btree.h

#define ElemType int

struct Node {
    ElemType data;
    struct Node *left;
    struct Node *right;
};

struct Node *new_node(ElemType data);

struct Node *insert_node(struct Node *b, ElemType data);

void pre_order(struct Node *b);

void in_order(struct Node *b);

void pos...

Read more

C++STL之vector


#include <iostream>
#include <vector>
#include <algorithm>


void print(int n) {
    std::cout << n << " ";
}

int main() {
    // vector线性容器,类似数组,可以自动存储元素,自动增长和减小空间,可以被迭代
    int a[7] = {1, 2, 3, 4, 5, 6, 7};
    // iv(first:a,last:a+7)
    std::vector<...

Read more