给定一个整数X和整数A0,A1,…,AN-1,后者已经预先排序并在内存中,求下标i使得Ai = X , 如果X不在数据中则返回i = -1 。明显的解法是从左往右扫描,花费线性时间。但是这个算法没有用到该表已经排序这个事实。折半检索(binary search,二分法检索)策略:/** * Perf...
分类:
其他好文 时间:
2014-07-16 23:25:47
阅读次数:
233
命名格式:arch[-vendor][-os]-abiarch:CPU的架构vendor:工具链的供应商os: 目标上运行的操作系统,不同的操作系统对应着不同的C库,例如newlib、glibc,、crt0等等。在程序的连接阶段将连接这些不同的C库。abi: 指定应用程序的二级制文件接口规定,确保不...
分类:
其他好文 时间:
2014-07-16 23:11:33
阅读次数:
189
DR模式中LVS主机与实际服务器都有一块网卡连在同一物理网段上。IP分配VIP:10.10.3.170RIP1:10.10.3.140RIP2:10.10.3.1411、安装所需的依赖包yum install -y wget make kernel-devel gcc gcc-c++ libnl* ...
分类:
其他好文 时间:
2014-07-10 13:35:54
阅读次数:
597
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
分类:
其他好文 时间:
2014-07-10 11:24:15
阅读次数:
229
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth...
分类:
其他好文 时间:
2014-06-28 10:07:19
阅读次数:
208
#include "my_file.h"
//将文件内容拷贝到指定文件
int mycopy(const char *filename)
{
ifstream infile(filename, ios::binary);
ofstream outfile("TRACE.txt", ios::binary);
if (!infile.is_open() || !outfile...
分类:
其他好文 时间:
2014-06-28 08:46:56
阅读次数:
199
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:
Given the below binary tree and sum
= 22,
5
/ ...
分类:
其他好文 时间:
2014-06-28 07:31:28
阅读次数:
214
学习过C语言的同学都知道,再写代码的时候,位操作运算总比算数运算操作快,
本文就是用C语言提供的位运算实现两个数的加法。
本文使用的代码都经过调试正常并且能够运行,调试环境centos gcc 一下是实现代码,以及测试结果:
#include
#include
int main(int argc, char **argv)
{
int add_a,add_b;...
分类:
其他好文 时间:
2014-06-28 07:26:38
阅读次数:
183
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root ...
分类:
其他好文 时间:
2014-06-27 23:13:24
阅读次数:
218
Iterative ways: 1 int binarySearch (int[] a, int x) { 2 int low = 0; 3 int high = a.length - 1; 4 int mid; 5 6 while (low x) {12 ...
分类:
其他好文 时间:
2014-06-27 22:27:06
阅读次数:
361