数据结构学习笔记(3)串的插入的c++实现

 实现了向一个字符串中插入另一个字符串,这边的字符串时自己定义的类型。

如再aasdasd中的第2个位置插入ppp,就变为aapppsdasd;

// HSTRING.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "type.h"
#include 
#include
#include
using namespace std;
class HString
{
public:
	HString();
	~HString();
	Status StrInsert(int pos, HString T) {
	//将T插入到本对象的pos位置
		if (pos<1 || pos>length - 1)return ERROR;
		if (T.ch)//如果T非空
		{
			char * ch_tmp = new char[length + T.length];
			memcpy(ch_tmp, ch, length);
			for (int i = length - 1; i >= pos - 1; i--) {
				ch_tmp[i + T.length] = ch_tmp[i];
			}
			//现在pos..。length已经空了,下面进行插入
			for (int i = 0; i 

运行结果ruxi如下图所示:

数据结构学习笔记(3)串的插入的c++实现_第1张图片

你可能感兴趣的:(数据结构)