![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 68
Jack_Lpz
Jack_Li style
展开
-
汗诺塔问题
#include using namespace std; void hanoi(int n, char a, char b, char c) { if(1 == n) //the last step: from a to c { cout " } else { hanoi(n-1, a, c, b); //use b as a原创 2014-09-05 20:31:24 · 1321 阅读 · 0 评论 -
菲波那契数列
#include using namespace std; int fab(int n) { int *arr = new int[n]; arr[0] = 1; arr[1] = 2; int result = 0; for(int i=2; i arr[i]= arr[i-1] + arr[i-2];原创 2014-09-06 23:16:18 · 469 阅读 · 0 评论 -
各类排序算法(已包装好)
以下是各类排序算法(本人在VS2008下已经验证),还有一些不足(例如模板化) 思想比代码本身重要.....呵呵 sort.h #ifndef SORT_H #define SORT_H const int maxNum = 100; class Diff_Sort { public: Diff_Sort(); virtual void原创 2014-09-06 22:15:37 · 558 阅读 · 0 评论 -
两个数据交换的几种方式
#include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int a = 2; int b = 3; /* 方法1:利用中间变量 temp int temp = a; a = b; b = temp; */ /* 方法原创 2014-09-06 22:17:05 · 638 阅读 · 0 评论 -
杨辉三角
#include #include using namespace std; //#include const int N = 6; //use position and computer it's number long computer(int n, int r) { long p = 1; for(int i=1; i p = p原创 2014-09-08 23:05:06 · 442 阅读 · 0 评论 -
八个硬币中找假
#include using namespace std; #include //用于随机产生的硬币重量 #include const int N = 8; int calCoin(int *arr); int main() { int* arr = new int[N]; for(int i=0; i { arr原创 2014-09-21 12:00:02 · 714 阅读 · 0 评论 -
三色棋
#include #include using namespace std; void swap(char &x, char &y) { char temp = y; y = x; x = temp; } int main() { char color[] = {'r', 'w', 'b', 'w', 'w', 'b', 'r',原创 2014-09-09 19:40:58 · 1008 阅读 · 0 评论 -
字符串的查找算法
//包括BF算法 KMP算法 Hash算法 #include "stdafx.h" #include #include using namespace std; static int find(char S[],char T[], int pos) { int i = pos; int j = 0; int sLen = strlen(S); int tLen =原创 2014-09-12 23:15:57 · 606 阅读 · 0 评论 -
x的n次方求解 与 优化
#include "stdafx.h" #include using namespace std; int power(int x, int n) //注意数值不要大 整数表示范围有限 { int y=x; while(n>1) { y *= x; n--; } return y; } int fastPower(int x, int n)原创 2014-09-12 23:18:53 · 2280 阅读 · 0 评论