摘要: 1、函数名:memset 所属头文件: 用法:void*memset(void*s,charch,unsignedn);对于对int之类的数组,只能用memset对其初始化为0或-1初始化,如:1 int a[]; 2 memset(a,0,sizeof(a)):3 //sizof(a)=sizeof(int)*n; 而对于char型,可以赋任何字符。如:1 char a[]; 2 memset(a,'0',sizeof(a));//sizeof(a)=1*n;2、函数名:fill_n 所属头文件: 用法:template voidfill_n(OutputIt first, 阅读全文
posted @ 2013-11-02 17:05 hbiner 阅读(482) 评论(0) 推荐(0)
摘要: 题目链接:http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解法:递归;父节点的深度等于左子树/右子树中深度大者+1 1 /** 2 * Definition for binary tree 3 * stru.. 阅读全文
posted @ 2013-11-02 16:57 hbiner 阅读(151) 评论(0) 推荐(0)
摘要: 题目链接:http://oj.leetcode.com/problems/single-number-ii/Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?解法:由于数组中所有元素都是整型,整型长度为32位,可以用一个数组count 阅读全文
posted @ 2013-11-02 16:51 hbiner 阅读(190) 评论(0) 推荐(0)
摘要: 链接:http://oj.leetcode.com/problems/single-number/Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?解法:可以根据异或运算的配对性定理可以解此题.配对性定理可以详见:http://wenku.bai 阅读全文
posted @ 2013-10-29 10:23 hbiner 阅读(144) 评论(0) 推荐(0)
摘要: No1 vector();No2 vector( const vector& c );No3 explicit vector( size_type num, const TYPE& val = TYPE() No4 template vector( input_iterator start, input_iterator end );No5 float fp_values[] = { 0.1, 0.2 , 0.3, 0.4}; vector fp_vector(fp_values, fp_values + 4);N01默认构造函数不带参数,只创建一个 vector 实例... 阅读全文
posted @ 2013-08-16 14:54 hbiner 阅读(1639) 评论(0) 推荐(0)
摘要: 本文转自:http://blog.csdn.net/wuhong40/article/details/6155838,感谢原文作者。前不久在阅读Quake3源代码的时候,看到一个陌生的函数:setjmp,一番google和查询后,觉得有必要针对setjmp和longjmp这对函数写一篇blog,总结一下。setjmp和longjmp是C语言独有的,只有将它们结合起来使用,才能达到程序控制流有效转移的目的,按照程序员的预先设计的意图,去实现对程序中可能出现的异常进行集中处理。先来看一下这两个函数的定义吧:setjmp和longjmp的函数原型在setjmp.h中函数原型: int setjmp( 阅读全文
posted @ 2013-08-16 10:10 hbiner 阅读(5436) 评论(0) 推荐(1)
摘要: 1、sprintf与printf,fprintf为三兄弟。其中printf输出到屏幕,fprintf输出到文件,而sprintf输出到字符串中。通常情况下,屏幕是可以输出的,文件也可以写的(除非磁盘满或硬件损坏),但字符串就不一定了,你必须保证写入的字符串有足够的空间。多大才算足够大呢?就是要比字符个数加1,因为字符串后还有个空字符'\0'的结束符。2、函数strlen的作用是获取字符串s的实际长度。如果char str[20] = "abcd";则strlen(str)为4(不包括末位的空字符),而不是20(sizeof才是此值,表字符数组所占空间大小), 阅读全文
posted @ 2013-08-02 17:35 hbiner 阅读(134) 评论(0) 推荐(0)
摘要: warning c4627:"#include stdafx.h":在查找预编译头使用时跳过原因:1、没有添加 #include "stdafx.h"2、#include "stdafx.h" 必须添加到.cpp文件的第一行。不能将其他头文件比如#include放在它的前面。3、每个.cpp文件都必须有#include "stdafx.h" 阅读全文
posted @ 2013-07-24 22:25 hbiner 阅读(120) 评论(0) 推荐(0)