C++String类的实现


#include <cstddef>
#include <cstring>
using namespace std;

class String
{
public:
    String(const char *str = NULL); // 普通构造函数
    String(const String &other);    // 复制构造函数
    ~String();
    String &operator=(const String &other); // 赋值函数重构"="
    String &...

Read more

C++类的继承


#include <iostream>

class Box
{
public:
    // 构造函数
    Box(int h = 2, int w = 2, int len = 2);
    // 析构函数
    ~Box();
    int volume();

protected:
    int height, width, length;
};

Box::Box(int h, int w, int len)
{
    height = h;
    width = w;
    length = len;
}

Box::~Box()
{
    s...

Read more

C++类模板案例


#include <iostream>
#include <stdlib.h>

template <class T>

class Operation
{
private:
    T x, y;

public:
    Operation(T a, T b)
    {
        x = a;
        y = b;
    }
    T add();
    T sub();
};

template <class T>
T Operation<T>::add()
{
    return x + y;
}...

Read more

C语言字符串常用方法


// 字符长度
int strLenght(char *s) {
  int n = 0;
  while (*s != '\0') {
    n++;
    s++;
  }
  return n;
}

// 复制字符串 s2->s1
char *strCopy(char *s1, char *s2) {
  char *p = s1;
  while (*s2 != '\0') {
    *p = *s2;
    s2++;
    p++;
  }
  *p = '\0';
  return s1;
}

// 拼接字...

Read more

顺序队列的定义与方法


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

#define MaxSize 100
#define bool char
#define True 1
#define False 0

typedef int ElemType;

typedef struct SeqQueue {
    ElemType data[MaxSize];
    int front, rear; // 队头、队尾指针
} SQ;


void initSeqQueue(SQ *sq) {
    sq->front = 0;
    sq-&...

Read more

顺序栈的定义与基础操作


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

#define MaxSize 10
#define bool char
#define True 1
#define False 0

typedef int ElemType;

// 顺序栈类型定义
typedef struct stack {
    ElemType data[MaxSize];
    int top;
} SeqStack;


void init(SeqStack *s) {
    s->top = -1;
};

bool is_empty(S...

Read more

栈的链式存储结构及基本操作


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

#define MaxSize 10
#define ElemType int
#define bool char
#define True 1
#define False 0

struct node {
    ElemType data;
    struct node *next;
};

struct node *top;

void init() {
    top = NULL;
}

bool is_empty() {
    if (top == NULL) {
  ...

Read more

Cmake基础用法


# CMakeLists.txt 文件常用配置
# cmake最小版本
cmake_minimum_required(VERSION 3.10)

# 项目名
project(demo1)

# 设置bin目录
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

# 将源文件目录下所有源文件保存到SRC_LIST
aux_source_directory(src SRC_LIST)

# 指定头文件目录
include_directories(include)

# 将所有源文件编译成二进制程序
add_executable(d...

Read more