mirror of
https://github.com/Didnelpsun/CS408.git
synced 2026-02-11 06:35:54 +08:00
更新串
This commit is contained in:
118
Code/CPP-Code/head/sequence_string.h
Normal file
118
Code/CPP-Code/head/sequence_string.h
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "head.h"
|
||||
|
||||
// 顺序串
|
||||
class SequenceString{
|
||||
private:
|
||||
// 数据
|
||||
char* _data{};
|
||||
// 长度
|
||||
int _length{};
|
||||
// 最大容量
|
||||
int _max_size{};
|
||||
public:
|
||||
// 设置数据
|
||||
bool SetData();
|
||||
|
||||
bool SetData(int max_size);
|
||||
|
||||
bool SetData(char *character);
|
||||
|
||||
bool SetData(int index, char character);
|
||||
|
||||
// 获取数据
|
||||
char* GetData();
|
||||
|
||||
char GetData(int index);
|
||||
|
||||
// 长度自加
|
||||
bool SetLength();
|
||||
|
||||
// 设置长度
|
||||
bool SetLength(int length);
|
||||
|
||||
// 获取长度
|
||||
int GetLength() const;
|
||||
|
||||
// 设置最大容量
|
||||
bool SetMaxSize();
|
||||
|
||||
bool SetMaxSize(int max_size);
|
||||
|
||||
// 获取最大容量
|
||||
int GetMaxSize() const;
|
||||
|
||||
// 构造函数
|
||||
SequenceString();
|
||||
|
||||
explicit SequenceString(int max_size);
|
||||
};
|
||||
|
||||
bool SequenceString::SetData() {
|
||||
this->_data = new char[MAXSIZE];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceString::SetData(int max_size) {
|
||||
this->_data = new char[max_size];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceString::SetData(char * character) {
|
||||
this->_data = character;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceString::SetData(int index, char character) {
|
||||
this->_data[index] = character;
|
||||
return true;
|
||||
}
|
||||
|
||||
char *SequenceString::GetData() {
|
||||
return this->_data;
|
||||
}
|
||||
|
||||
char SequenceString::GetData(int index) {
|
||||
return this->_data[index];
|
||||
}
|
||||
|
||||
bool SequenceString::SetLength() {
|
||||
this->_length++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceString::SetLength(int length) {
|
||||
this->_length = length;
|
||||
return true;
|
||||
}
|
||||
|
||||
int SequenceString::GetLength() const {
|
||||
return this->_length;
|
||||
}
|
||||
|
||||
bool SequenceString::SetMaxSize() {
|
||||
this->_max_size = MAXSIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SequenceString::SetMaxSize(int max_size) {
|
||||
this->_max_size = max_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
int SequenceString::GetMaxSize() const {
|
||||
return this->_max_size;
|
||||
}
|
||||
|
||||
SequenceString::SequenceString() {
|
||||
this->SetData();
|
||||
this->SetMaxSize();
|
||||
this->SetLength(0);
|
||||
}
|
||||
|
||||
SequenceString::SequenceString(int max_size) {
|
||||
this->SetData(max_size);
|
||||
this->SetMaxSize();
|
||||
this->SetLength(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user