数据结构复习10 串

string.h

/* string DIY process must be the most important in our job */
/* string is a sequent list limited */
/* string.h
--int strcpy(s1,s2) copy s2 content to s1 **if s1 bigger than s2,the front content will be reaplaced,with remain the last content
--int strcat(s1,s2) put s2 to s1's rear part
--int strlen(s) count the size of string
--char* _strdup(s) char *p=_strdup(s); generate string by an another string
--int strcmp(s1,s2) 
 */

字符串ADT

/* string DIY process must be the most important in our job */
/* string is a sequent list limited */
/* string.h
--int strcpy(s1,s2) copy s2 content to s1 **if s1 bigger than s2,the front content will be reaplaced,with remain the last content
--int strcat(s1,s2) put s2 to s1's rear part
--int strlen(s) count the size of string
--char* _strdup(s) char *p=_strdup(s); generate string by an another string
--int strcmp(s1,s2) 
 */
 
#define MAX 1000
typedef char OrderString[MAX];

class MyString{
	protected:
	char *ch;
	int length;
	int maxSize;
	public:
	MyString(int size=MAX);
	MyString(const char *init);//strlen strcpy
	MyString(const MyString& ms);//strlen strcpy
	~MyString(){delete []ch;}
	int Length()const{return length;}
	MyString& operator()(int pos,int len);
	int operator==(MyString& ms)const{return strcmp(ch,ms.ch)==0;}
	int operator!=(MyString& ms)const{return strcmp(ch,ms.ch)!=0;}
	int operator!()const(return length==0;}
	MyString& operator=(const MyString& ms);
	MyString& operator+=(const MyString& ms);//strcat
	char& operator[](int i);
	int KMPFind(MyString &pat)const;
	void getNext(int next[]);
};

MyString::MyString(int size):maxSize(size){
	ch=new char[maxSize+];
	assert(ch!=NULL);
	length=0;ch[0]='\0';
}

MyString(const char *init){
	int len=strlen(init);
	maxSize=(len>MAX)?len:MAX;
	ch=new char[maxSize+1];
	assert(ch!=NULL);
	length=len;
	strcpy(ch,init);
}

MyString MyString::(const MyString &ms){
	maxSize=ms.maxSize;
	ch=new char[ms.length+1];
	assert(ch!=NULL);
	length=ms.length;
	strcpy(ch,ms.ch);
}

MyString MyString::operator()(int pos,int len){
	MyString temp;
	if(pos<0 || pos+len>=maxSize+1 || len<0){
		temp.length=0;temp.ch[0]='\0';
	}else{
		//len in sense
		if(pos+len>=length+1)
			len=length-pos;
		//get substr
		temp.len=len;
		for(int i=0,j=pos;i<len;i++,j++)
			temp.ch[i]=ch[j];
		temp.ch[len]='\0';
	}
	return temp;
}

MyString& MyString::operator=(const MyString& ms){
	if(this==&ms){
		return ms;
	}
	delete []ch;
	ch=new char[ms.maxSize+1];
	assert(ch!=NULL);
	length=ms.length;
	strcpy(ch,ms.ch);
	return *this;
}

MyString& MyString::operator+=(const MyString& ms){
	//strcat
	//bigger than maxSize
	char *temp=ch;
	int n=length+ms.length;
	int m=(n>=maxSize)?maxSize:n;
	ch=new char[m];
	assert(ch!=NULL);
	//catch
	maxSize=m;
	length=n;
	strcpy(ch,temp);
	strcat(ch,ms.ch);
	delete []temp;
	return *this;
	
}

char& MyString::operator[](int i){
	assert(!(i<0||i>=length));
	return ch[i];
}

int MyString::KMPFind(MyString &pat,int k,int next[])const{
	int posT=k;
	int posP=0;
	int lenP=pat.length;
	int lenT=length;
	while(posT<lenT&&posP<lenP){
		if(posP==-1||pat.ch[posP]==ch[posT]){
			posT++;posP++;//B-F part
		}
		else{
			posP=next[posP];//K-M-P part
		}
	}
	if(posT>=lenT || posP<lenP)
		//matching failed
		return -1;
	else
		//return first index in Tstring
		return posT-lenP;
}

void MyString::getNext(int next[]){
	int j=0;
	int k=-1;
	int lenP=length;
	next[0]=-1;
	while(j<lenP){
		if(k==-1||ch[j]==ch[k]){
			j++;k++;
			next[j]=k;
		}else{
			
			k=next[k];
		}
	}
}
(Kriging_NSGA2)克里金模型结合多目标遗传算法求最优因变量及对应的最佳自变量组合研究(Matlab代码实现)内容概要:本文介绍了克里金模型(Kriging)与多目标遗传算法NSGA-II相结合的方法,用于求解最优因变量及其对应的最佳自变量组合,并提供了完整的Matlab代码实现。该方法首先利用克里金模型构建高精度的代理模型,逼近复杂的非线性系统响应,减少计算成本;随后结合NSGA-II算法进行多目标优化,搜索帕累托前沿解集,从而获得多个最优折衷方案。文中详细阐述了代理模型构建、算法集成流程及参数设置,适用于工程设计、参数反演等复杂优化问题。此外,文档还展示了该方法在SCI一区论文中的复现应用,体现了其科学性与实用性。; 适合人群:具备一定Matlab编程基础,熟悉优化算法和数值建模的研究生、科研人员及工程技术人员,尤其适合从事仿真优化、实验设计、代理模型研究的相关领域工作者。; 使用场景及目标:①解决高计算成本的多目标优化问题,通过代理模型降低仿真次数;②在无法解析求导或函数高度非线性的情况下寻找最优变量组合;③复现SCI高水平论文中的优化方法,提升科研可信度与效率;④应用于工程设计、能源系统调度、智能制造等需参数优化的实际场景。; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法实现过程,重点关注克里金模型的构建步骤与NSGA-II的集成方式,建议自行调整测试函数或实际案例验证算法性能,并配合YALMIP等工具包扩展优化求解能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值