摘要: /*设要排序的数组是A[0]……A[N-1],首先任意选取一个数据(通常选用第一个数据)作为关键数据,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这个过程称为一趟快速排序。一趟快速排序的算法是:1)设置两个变量I、J,排序开始的时候:I=0,J=N-1;2)以第一个数组元素作为关键数据,赋值给key,即 key=A[0];3)从J开始向前搜索,即由后开始向前搜索(J=J-1),找到第一个小于key的值A[J],并与A[I]交换;4)从I开始向后搜索,即由前开始向后搜索(I=I+1),找到第一个大于key的A[I],与A[J]交换;5)重复第3、4、5步,直到 I=J; (3, 阅读全文
posted @ 2011-11-24 12:28 hibernate3例子 阅读(136) 评论(0) 推荐(0) 编辑
摘要: //非递归求斐波那契数列 #include<iostream>using namespace std;long f(int index){ if( index==1 || index == 2){ return 1; } long f1 = 1L; long f2 = 1L; long f = 0; for( int i = 0;i < index-2;i ++){ f = f1+f2; f1 = f2; f2 = f; } retu... 阅读全文
posted @ 2011-11-24 12:26 hibernate3例子 阅读(164) 评论(0) 推荐(0) 编辑
摘要: //LCS算法,最长公共子序列 来自《算法导论》#include<iostream>#include<cstdlib>#include<cmath>#define N 105char s[N+1][N+1];using namespace std;int LCS( const char*s1,const char*s2){ int m = strlen(s1); int n = strlen(s2); int i,j; s[0][0]=0; for( i = 0;i <= m;i++){ s[i][0]=0; } for( j... 阅读全文
posted @ 2011-11-24 12:24 hibernate3例子 阅读(236) 评论(0) 推荐(0) 编辑