顺序存储串的基本操作

//几个算法写得老阔痛#ifndef PCH_H#define PCH_H#include<cstdlib>#include<stdio.h>#include<malloc.h>#include<iostream>#include<math.h>#include<string>//?#include<t...
摘要由CSDN通过智能技术生成
//几个算法写得老阔痛
#ifndef PCH_H
#define PCH_H
#include<cstdlib>
#include<stdio.h>
#include<malloc.h>
#include<iostream>
#include<math.h>
#include<string>//?
#include<time.h>//時間計算
constexpr auto MAXSIZE = 255;
constexpr auto OK = 1;
constexpr auto ERROR = 0;
constexpr auto CHUNKSIZE = 80;//可由用户定义的块大小
constexpr auto TSIZE = 5;
typedef int Status;
	//--------串的定长顺序存储结构----------
typedef struct {
   
	char ch[MAXSIZE + 1];//存储串的一维数组,最后一位给'\0'
	int length;//串的当前长度
}SString;//静态定义,编译时就确定了串的空间大小
	//--------heap 堆式顺序存储结构---------
typedef struct {
   
	char *ch;//按照串长分配存储区,否则ch为NULL
	int length;//串的当前长度
}HString;
//----------串的块链存储结构---------
typedef struct Chunk{
   
	//需要大量移动字符
	char ch[CHUNKSIZE];
	struct Chunk *next;
}Chunk;
typedef struct
{
   //串操作实现与线性表在链式存储结构中操作类似
	Chunk *head,*tail;//串头串尾指针
	int length;//串的当前长度
}LString;
//---Brute-Force 算法---
int Index_BF(SString S/*主串*/, SString T/*模式串*/, int pos/*查找起始位置*/);
Status StrPrint(SString T);
Status StrInit(SString &T);
Status StrAssign(SString &T,char *ch);//ch为字符串常量,生成值为ch的串
Status StrCopy(SString &T, SString S);//由串S复制得串T
Status StrEmpty(SString S);//若S为空串返回true
Status StrCompare(SString S, SString T);
/*S>T返回>0,S=T返回=0,S<T返回<0*/
Status StrLength(SString S);
Status ClearString(SString &S);//将S清为空串
Status Concat(SString &T,SString S1,SString S2);//T返回S1和S2联结而成的新串
Status SubString(SString &Sub, SString S,int pos, int len);
//用串sub返回串S第pos位置长度len的串
void Replace(SString &S, SString T, SString V);//用V替换所有与T相同不重叠子串
Status StrInsert(SString &S, int pos, SString T);//在串S的第pos位置之前插入串T
Status StrDelete(SString &S, int pos, int len);//从串S中删除第pos位置起长度为len的子串
Status DestroyString(SString &S);//串S存在,串S销毁
#endif
-------------------------------------------------
// pch.cpp: 与预编译标头对应的源文件;编译成功所必需的

#include "pch.h"

// 一般情况下,忽略此文件,但如果你使用的是预编译标头,请保留它。

int Index_BF(SString S, SString T, int pos)
{
   
	//BF算法
	//返回模式T在主串S中第pos个字符开始 第一次出现的位置
	//不存在则返回0
	int i = pos-1;//初始化i,主串S中第pos个字符
	int j 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值