数据结构
小菜根win
技术爱好者
展开
-
顺序查找
type PStringArray = array of String;// sequential searchfunction SequenSearch(aStrs: PStringArray; aCount: Integer; const aName: string): Integer;var i: Integer;begin for i := 0原创 2013-10-26 00:36:04 · 477 阅读 · 0 评论 -
选择排序
选择排序转载 2016-09-02 19:01:01 · 175 阅读 · 0 评论 -
牛顿迭代法求方程根
/* *方程:2*x*x*x - 4*x*x + 3*x - 6 = 0; */#include #include using namespace std;int main(void){ double x0, x1, f0, f1; x0 = 2.5; //任意赋值 x1 = 1.5; while(fabs(x0-x1)>1e-6){原创 2012-10-27 09:01:11 · 739 阅读 · 0 评论 -
二分法求方程根
/* *方程:2*x*x*x - 4*x*x + 3*x - 6 = 0; */#include #include using namespace std;double f(double x);int main(void){ double x1 = -10, x2 = 10, x; while(fabs(x1-x2)>=1e-6){ x = (x1+x2)/2原创 2012-10-27 09:21:20 · 952 阅读 · 0 评论 -
Fibonacci数列
/* *非递归实现 */#include int main(void){ int i; int f[20] = {1, 1}; for(i=2; i<20; i++){ f[i] = f[i-1] + f[i-2]; } for(i=0; i<20; i++){ if(0==i%5){ std::cout << std::endl; } std::c原创 2012-10-27 09:28:00 · 392 阅读 · 0 评论 -
冒泡排序法
/* *冒泡排序法 */#include using namespace std;int main(){ int a[10]; int i, j, temp; cout << "输入10个整数:\n"; for(i=0; i<10; i++){ cin >> a[i]; } /*排序*/ for(i=0; i<9; i++){ for(j=0; j<9-i;转载 2012-10-27 10:06:16 · 460 阅读 · 0 评论 -
大整数乘法问题
#include #include using namespace std;// 返回位数size1 + size2int* multi(int *num1, int size1, int *num2, int size2) { int size = size1 + size2; int *ret = new int[size]; int i = 0; memset(ret转载 2015-08-09 13:45:32 · 590 阅读 · 0 评论 -
荷兰国旗问题
/** * 荷兰国旗问题 * 解题的基本策略:变了两个颜色区域,如果颜色条不属于所在的区域,则交换一个属于该 * 区域的颜色条。每一次都是必要的交换,从而实现最小交换次数。*/#include using namespace std;const int N = 100;int flag[N]; // 国旗颜色条数组int pre[N]; // 记录该红条的前红转载 2015-08-09 15:06:17 · 580 阅读 · 0 评论 -
二分查找
type PStringArray = array of String;// before you use the method,// the objects you will search have to be sort ascendingfunction BinarySearch(Strs: PStringArray; Count: Integer; con原创 2013-10-26 01:06:09 · 471 阅读 · 0 评论 -
插入排序
class ArrayIns { private long[] a; private int nElems; public ArrayIns(int max) { a = new long[max]; nElems = 0; } public void insert(long value) { a[nEle转载 2016-09-02 19:03:28 · 212 阅读 · 0 评论