1 Star 0 Fork 0

郑玉强/dataStructure

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cyber_dash_string.h 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
#pragma once
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
const size_t DEFAULT_SIZE = 128;
class String
{
friend ostream& operator<<(ostream& os, const String& str);
friend bool operator==(const String& str1,const String& str2);
friend bool operator!=(const String& str1,const String& str2);
friend bool operator<(const String& str1,const String& str2);
friend bool operator<=(const String& str1, const String& str2);
friend bool operator>(const String& str1, const String& str2);
friend bool operator>=(const String& str1, const String& str2);
private:
char* mem_data_; // 字符数组
int length_; // 当前字符串长度
size_t size_; // 最大长度
public:
explicit String(size_t size = DEFAULT_SIZE);
explicit String(const char* mem_data);
// 拷贝构造函数
String(const String& str);
~String() { delete[] this->mem_data_; }
int length() const { return this->length_; }
size_t size() const { return this->size_; }
// 这个版本用于在 常量对象 上调用
// const MyString str("hello");
// char c = str[0]; // 可以读取 str[0],但不能修改
const char& operator[](size_t index) const;
// 这个版本用于在 非常量对象 上调用
// MyString str("hello");
// str[0] = 'H'; // 可以修改 str[0]
char& operator[](size_t index);
String& operator=(const String& src_str);
String& operator+=(String& str);
// 暴力匹配
int bruteForceMatch(const String& pattern, int offset) const;
int kmpMatchByCyberDash(const String& pattern, int offset) const;
int kmpMatch(const String& pattern, int offset) const;
// 求next数组
int* kmpNext() const;
// 求next数组(cyberdash版本)
int* kmpNextByCyberDash() const;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zheng-yuqiang_lyg_cn/data-structure.git
git@gitee.com:zheng-yuqiang_lyg_cn/data-structure.git
zheng-yuqiang_lyg_cn
data-structure
dataStructure
dev01

搜索帮助