随笔分类 -  数据结构与算法

七、递归-折半查找
摘要:#include using namespace std;int BinarySearch(int List[], int value, int low, int height);int main(){ int test[] = {1,2,3,4,5,6,7,8,9,11,13,15,21,3... 阅读全文
posted @ 2015-03-10 14:45 箭已离弓 阅读(196) 评论(0) 推荐(0)
六、递归-阶乘
摘要:自己调用自己。#include using namespace std;int Factorial(int value);int main(){ int number = Factorial(5); cout << "Factorial" << number << endl; sy... 阅读全文
posted @ 2015-03-10 13:48 箭已离弓 阅读(117) 评论(0) 推荐(0)
五、二分查找
摘要:前提:数据先排序。#include using namespace std;int BinarySearch(int List[], const int size, const int value);int main(){ int a[] = {1,2,3,4,5,6,7,8,11,23,43... 阅读全文
posted @ 2015-03-10 12:26 箭已离弓 阅读(123) 评论(0) 推荐(0)
四、顺序查找
摘要:查找方式:顺序查找和折半查找(二分查找);如果数据已排序,可使用折半查找和顺序查找;如果数据未排序,使用顺序查找。 顺序查找速度慢。#include using namespace std;int SequentialSearch(int List[], const int size, con... 阅读全文
posted @ 2015-03-10 11:10 箭已离弓 阅读(119) 评论(0) 推荐(0)
三、选择排序
摘要:从当前未排序的整数中找一个最小的整数,将它放在已排序的整数列表的最后。要点:选择排序选最小的,往左边选。#include using namespace std;void SelectSort(int List[],int size);int main(){ int a[] = {2,3,1,... 阅读全文
posted @ 2015-03-10 10:47 箭已离弓 阅读(101) 评论(0) 推荐(0)
二、冒泡排序
摘要:从左向右扫描数据,选择最大的数据,放在右边。要点:比较相邻的两个数,如果左边的数大于右边的数就进行交换。#include using namespace std;void BubbleSort(int list[], int n);int main(){ int a[] = {9,8,7,6,... 阅读全文
posted @ 2015-03-10 09:31 箭已离弓 阅读(141) 评论(0) 推荐(0)