【算法学习】顺序串及快速排序算法
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
相关文章推荐
- 快速排序
- C#快速排序算法实例分析
- C++快速排序的分析与优化详解
- js实现数组冒泡排序、快速排序原理
- php简单实现快速排序的方法
- Java 快速排序(QuickSort)原理及实现代码
- 快速排序和分治排序介绍
- java 算法之快速排序实现代码
- Java实现快速排序算法(Quicktsort)
- Java中的数组排序方式(快速排序、冒泡排序、选择排序)
- 快速排序的原理及java代码实现
- C/C++实现快速排序的方法
- c语言实现冒泡排序、希尔排序等多种算法示例
- 深入单链表的快速排序详解
- C++实现八个常用的排序算法:插入排序、冒泡排序、选择排序、希尔排序等
- JavaScript实现快速排序的方法
- C#使用委托实现的快速排序算法实例
- C语言的冒泡排序和快速排序算法使用实例
- javascript与Python快速排序实例对比
- php实现快速排序的三种方法分享