上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页
摘要: 将十进制数转换为二进制数:非递归算法: 1 void translate(int n) //将10进制转换为8位的二进制 2 { 3 int a[10]; 4 int i,j; 5 i=0; 6 while(1) 7 { 8 a[i++]=n%2; 9 if(n/2==0) break; 10 n/=2; 11 } 12 i--; 13 for(j=1; j=0; j--) 18 { 19 printf("%d",... 阅读全文
posted @ 2013-10-01 17:46 cpoint 阅读(341) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 8 int Insert_search(int *a, int key, int n) 9 {10 int pos, low, high;11 low = 0,high = n - 1;12 while(low <= high){13 pos = ((key - a[low]) * (high - low )) / (a[high] - a[low]) + low;14 if(a[pos] < key){15 ... 阅读全文
posted @ 2013-09-26 13:02 cpoint 阅读(1356) 评论(0) 推荐(0) 编辑
摘要: 斐波那契查找的核心是: 1)当key=a[mid]时,查找成功; 2)当keya[mid]时,新的查找范围是第mid+1个到第high个,此时范围个数为F[k-2] - 1个,即数组右边的长度,所以要在[F[k - 2] - 1]范围内查找。代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define MAXSIZE 20 8 9 void fibonacci(int *f) //构建斐波那契序列10 {11 f[0] = 1;12 f[1] = 1;13 for(int i ... 阅读全文
posted @ 2013-09-26 11:39 cpoint 阅读(2859) 评论(0) 推荐(0) 编辑
摘要: 在计算机科学中,折半搜索,也称二分查找算法、二分搜索,是一种在有序数组中查找某一特定元素的搜索算法。搜素过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。如果在某一步骤数组为空,则代表找不到。这种搜索算法每一次比较都使搜索范围缩小一半。复杂度分析时间复杂度折半搜索每次把搜索区域减少一半,时间复杂度为。(n代表集合中元素的个数)空间复杂度 。虽以递归形式定义,但是尾递归,可改写为循环。C代码如下: 1 #include 2 #include 3 #includ 阅读全文
posted @ 2013-09-26 01:40 cpoint 阅读(1199) 评论(0) 推荐(0) 编辑
摘要: 内存区域可以分为栈、堆、静态存储区和常量存储区,局部变量,函数形参,临时变量都是在栈上获得内存的,它们获取的方式都是由编译器自动执行的。利用指针,我们可以像汇编语言一样处理内存地址,C 标准函数库提供了许多函数来实现对堆上内存管理,其中包括:malloc函数,free函数,calloc函数和realloc函数。使用这些函数需要包含头文件stdlib.h。 四个函数之间的有区别,也有联系,我们应该学会把握这种关系,从而编出精炼而高效的程序。在说明它们具体含义之前,先简单从字面上加以认识,前3个函数有个共同的特点,就是都带有字符”alloc”,就是”allocate”,”分配”的意思,也就是给.. 阅读全文
posted @ 2013-09-25 20:32 cpoint 阅读(409) 评论(0) 推荐(0) 编辑
摘要: 假设以I和O分别代表入栈和出栈操作,设计一个算法判断任一给定的栈操作序列是否合法。(例如:IOIOIIOOIO)算法的设计思想:依次扫描出栈入栈操作序列,每扫描至一个位置,需检查出栈次数是否大于入栈次数,若大则非法。扫描结束后,再检查出栈次数与入栈次数是否相等,若不相等,则非法。C代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 char s[1000]; 8 9 /*10 * 判断一组入栈出栈操作序列是否合法的算法11 *12 **Tue Sep 17 2013 wuyudong 13 */14 15 ... 阅读全文
posted @ 2013-09-17 17:06 cpoint 阅读(2340) 评论(0) 推荐(0) 编辑
摘要: 一、对int类型数组排序int num[100];Sample:int cmp ( const void *a , const void *b ){return *(int *)a - *(int *)b;}qsort(num,100,sizeof(num[0]),cmp);二、对char类型数组排序(同int类型)char word[100];Sample:int cmp( const void *a , const void *b ){return *(char *)a - *(int *)b;}qsort(word,100,sizeof(word[0]),cmp);三、对double类型 阅读全文
posted @ 2013-08-20 00:26 cpoint 阅读(270) 评论(0) 推荐(0) 编辑
摘要: minix中关于如何判定一个字符的类型,如大写、小写、数字……如果采用传统的方法,如判断一个字母大写的方法:if(c>='A' && c'a') || (c'A') || (c>'0' && c<'9')) return true如果假设更多的局限,效率明显下降minix的做法是定义一个256元素的unsigned char _ctypes[]数组,由于8位需要8种属性分别描述,如下:#define _U 0x01 /* this bit is for upper- 阅读全文
posted @ 2013-08-19 14:37 cpoint 阅读(433) 评论(0) 推荐(0) 编辑
摘要: 描述To give you an IP address, it may be dotted decimal IP address, it may be 32-bit binary IP address.Is now required to give you an IP address, if the IP address is in dotted decimal output is 32-bit binary IP address,On the contrary, the output dotted decimal IP address.for example,the dotted decim 阅读全文
posted @ 2013-08-16 16:40 cpoint 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 假设以顺序存储结构实现一个双向栈,即在一维数组的存储空间中存在着两个栈,它们的栈底分别设在数组的两个端点。试编写实现这个双向栈tws的三个操作:初始化inistack(tws)、入栈push(tws,i,x)和出栈pop(tws,i)的算法,其中i为0或1,用以分别指示设在数组两端的两个栈.#include #include #define OK 1 #define OVERFLOW -1 #define ERROR 1 typedef int Status; typedef struct { int *base[2]; int *top[2]; }BDStack; Status In... 阅读全文
posted @ 2013-08-05 20:07 cpoint 阅读(589) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页
浏览次数:travelocity promotion codes