mirror of
https://github.com/Didnelpsun/CS408.git
synced 2026-06-16 06:56:54 +08:00
更新串
This commit is contained in:
@@ -2,5 +2,9 @@
|
||||
#define MAXSIZE 5
|
||||
// 定义默认值
|
||||
#define DEFAULTELEM '\0'
|
||||
// 定义默认串值
|
||||
#define DEFAULTCHAR '\0'
|
||||
// 定义串块链数据长度
|
||||
#define DATASIZE 4
|
||||
// 定义默认数据类型
|
||||
typedef char element_type;
|
||||
@@ -7,6 +7,12 @@ typedef struct LinkListNode {
|
||||
} LinkListNode, *LinkList;
|
||||
|
||||
// 初始化
|
||||
bool InitLinkList(LinkList &list) {
|
||||
list->data = DEFAULTELEM;
|
||||
list->next = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
LinkList InitLinkList() {
|
||||
auto list = (LinkList) malloc(sizeof(LinkList));
|
||||
list->data = DEFAULTELEM;
|
||||
@@ -14,12 +20,6 @@ LinkList InitLinkList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
bool InitLinkList(LinkList &list) {
|
||||
list->data = DEFAULTELEM;
|
||||
list->next = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 判空
|
||||
bool EmptyLinkList(LinkList list) {
|
||||
return list->next == nullptr && list->data == DEFAULTELEM;
|
||||
|
||||
@@ -4,8 +4,8 @@ typedef struct LinkStackNode{
|
||||
// 数据
|
||||
element_type data;
|
||||
// 指针
|
||||
struct LinkStackNode *next;
|
||||
} *LinkStack;
|
||||
LinkStackNode *next;
|
||||
} LinkStackNode, *LinkStack;
|
||||
|
||||
// 初始化
|
||||
LinkStack InitLinkStack(){
|
||||
|
||||
25
Code/Code/head/link_string.h
Normal file
25
Code/Code/head/link_string.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "head.h"
|
||||
|
||||
// 块链串结点
|
||||
typedef struct LinkStringNode {
|
||||
// 数据
|
||||
char *data;
|
||||
// 指针
|
||||
LinkStringNode *next;
|
||||
} LinkStringNode, *LinkString;
|
||||
|
||||
bool InitLinkString(LinkString &string) {
|
||||
string->data = (char *) malloc(sizeof(char) * DATASIZE);
|
||||
string->next = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
LinkString InitLinkString() {
|
||||
auto* string = (LinkString) malloc(sizeof(LinkString));
|
||||
string->data = (char *) malloc(sizeof(char) * DATASIZE);
|
||||
string->next = nullptr;
|
||||
return (LinkString &)string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
41
Code/Code/head/sequence_string.h
Normal file
41
Code/Code/head/sequence_string.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "head.h"
|
||||
|
||||
// 顺序串
|
||||
typedef struct {
|
||||
// 数据
|
||||
char *data;
|
||||
// 长度
|
||||
unsigned int length;
|
||||
// 最大容量
|
||||
unsigned int max_size;
|
||||
} SequenceString;
|
||||
|
||||
bool InitSequenceString(SequenceString &string) {
|
||||
string.data = (char *) malloc(sizeof(char) * MAXSIZE);
|
||||
string.max_size = MAXSIZE;
|
||||
string.length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InitSequenceString(SequenceString &string, int max_size) {
|
||||
string.data = (char *) malloc(sizeof(char) * max_size);
|
||||
string.max_size = max_size;
|
||||
string.length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
SequenceString InitSequenceString() {
|
||||
auto *string = (SequenceString *) malloc(sizeof(SequenceString));
|
||||
string->data = (char *) malloc(sizeof(char) * MAXSIZE);
|
||||
string->max_size = MAXSIZE;
|
||||
string->length = 0;
|
||||
return (SequenceString &) string;
|
||||
}
|
||||
|
||||
SequenceString InitSequenceString(int max_size) {
|
||||
auto *string = (SequenceString *) malloc(sizeof(SequenceString));
|
||||
string->data = (char *) malloc(sizeof(char) * max_size);
|
||||
string->max_size = max_size;
|
||||
string->length = 0;
|
||||
return (SequenceString &) string;
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../head/share_stack.h"
|
||||
#include "../head/sequence_queue.h"
|
||||
#include "../head/link_queue.h"
|
||||
#include "../head/sequence_string.h"
|
||||
#include "../head/link_string.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user