代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
寻找二进制
作者:
Dezai.CN
/ 发布于
2011/2/10
/
546
<div>* iterative version */ int search2(char *dict, char *name, int compChars) { int low, high, mid, result; low = 0; high = SIZE_OF_DICTIONARY - 1; while (low <= high) { mid = (low + high) / 2; result = strncmp(dict[mid], name, compChars); if (result > 0) { high = mid - 1; } else if (result < 0) { low = mid + 1; } else { return EXIT_SUCCESS; } } return NOT_FOUND; } <div>/* recursive version -- takes more space and, for my money, is more confusing */ int search(char *dict, char *name, int low, int high, int compChars) { if (high < low) { return NOT_FOUND; } int mid = (low + high) / 2; int result; result = strncmp(dict[mid], name, compChars); if (result > 0) { return searchName(name, low, mid-1, compChars); } else if (result < 0) { return searchName(name, mid+1, high, compChars); } else { return EXIT_SUCCESS; } return ERROR_SEARCH; } to c Binary Search by rtperson on Nov 12, 2008 Linked Lists in C // I coded this little piece of overkill for USACO's "Milk2" algorithm training problem. // I'm leaving out the actual solution to the problem, but am leaving in the basic // manipulations to the linked list itself.</div> <div> #include <stdio.h> #include <stdlib.h></div> <div>typedef struct timeNode timeNode; struct Node { int begin; /* i.e., the data part */ int end; timeNode *next; /* ptr to the next element */ };</div> <div>timeNode* addNode(timeNode *last, int begin, int end) { timeNode *node; node = (timeNode*)malloc(sizeof(timeNode)); node->begin = begin; node->end = end; node->next = NULL; if (last != NULL) { last->next = node; } return node; } <div>void insertNode(timeNode *before, int begin, int end) { timeNode *add = (timeNode*)malloc(sizeof(timeNode)); add->begin = begin; add->end = end; add->next = before->next; before->next = add; } <div>timeNode* insertBefore(timeNode *before, int begin, int end) { timeNode *add = (timeNode*)malloc(sizeof(timeNode)); add->begin = begin; add->end = end; add->next = before; return add; } <div> timeNode* deleteNode(timeNode *toDelete) { timeNode *retval = toDelete->next; free(toDelete); return retval; } <div></div>
试试其它关键字
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3