您的位置:首页 > 其它

【算法学习】顺序串及快速排序算法

2016-04-04 22:52 435 查看

快速排序

#ifndef SEQUENCE_STRING_H
#define SEQUENCE_STRING_H
#include<iostream>
using namespace std;
//只有被主函数包含的头文件才能进行报错检测
#define MAXSIZE_STRING 200

class sequenstring
{
public:
char data[MAXSIZE_STRING];
int len=0;
//代表该字符串现在有几个元素
sequenstring()
{
len = 0;
};
~sequenstring(){};
void create();
void show();
};
//使用了顺序表进行存储

void sequenstring::show()
{
int count = 0;
for (; count < len; count++)
{
cout << data[count] << " ";
}
cout << endl;
}

void sequenstring::create()
//为什么不能用string?
{
char temp_char;
cout << "请输入您所要创建的字符串 以#结束" << endl;
while ((cin >> temp_char) && (temp_char != '#'))
{
data[len] = temp_char;
len++;
}
}

sequenstring connect(sequenstring s1, sequenstring s2)
{
int count=0;
while (count!=s2.len)
{
s1.data[s1.len] = s2.data[count];
s1.len++;
count++;
}
return s1;
}//将s2连在s1后面

bool matching(int mom_count, sequenstring mom, sequenstring son)
{
int count_plus=0;
while (count_plus < son.len)
{
if (mom.data[mom_count + count_plus] == son.data[count_plus])
{
count_plus++;
}
else return false;
}
return true;

}//模式匹配pattern_matching的子函数

bool pattern_matching(sequenstring mom, sequenstring son)
{
int mom_count = 0;
int son_count = 0;
while (mom_count <= (mom.len - son.len))
{
if (matching(mom_count,mom,son))
{
return true;
}
else mom_count++;
}
return false;
}//模式匹配

//将复杂的问题用子函数层层剖析成简单的问题是解决算法问题的核心
//类的函数的子函数该怎么写?
#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  快速排序