C++
文章平均质量分 63
salutlu
这个作者很懒,什么都没留下…
展开
-
stl中的运算子
今天终于明白了下面这些的区别:Adaptor and conversion functionsNegatorsnot1Return negation of unary function object (function template )not2Return negation of binary function object (functio原创 2013-07-05 14:35:20 · 602 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the fo原创 2014-03-14 13:36:24 · 575 阅读 · 0 评论 -
Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from原创 2014-03-15 00:15:09 · 556 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as ma原创 2014-03-10 17:28:08 · 1260 阅读 · 0 评论 -
Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?这个for循环中的下标非常容易搞混,一定要区分清楚,到底固定哪一列,对于第二个for里面,i相当于常量原创 2014-03-15 21:19:55 · 601 阅读 · 0 评论 -
Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2014-03-15 12:50:19 · 688 阅读 · 0 评论 -
北大POJ题库使用指南
原文地址:北大POJ题库使用指南作者:clarence北大ACM题分类主流算法: 1、搜索 //回溯 2、DP(动态规划)//记忆化搜索 3、贪心 4、图论 //最短路径、最小生成树、网络流 5、数论 //组合数学(排列组合)、递推关系、质因数法 6、计算几何 //凸壳、同等安置矩形的并的面积与周长、凸包计算问题 8、转载 2014-04-17 16:57:31 · 1591 阅读 · 0 评论 -
C++中struct定义的一个小知识点
在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu;于是在声明变量的时候就可:Stu stu1;如果没有typedef就必须用struct Student stu1;来声明这里的Stu实际上就是struct Student的别名。另外这原创 2014-05-10 14:50:05 · 817 阅读 · 1 评论 -
Best Time to Buy and Sell Stock III
Total Accepted: 8400 Total Submissions: 38235 My SubmissionsSay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profi原创 2014-05-14 13:35:57 · 819 阅读 · 0 评论 -
Nginx调试汇总
这里是一个比较全的介绍:http://www.cnblogs.com/yjf512/archive/2012/05/10/2494635.html原创 2014-08-15 14:18:09 · 628 阅读 · 0 评论 -
GDB 调试C++异常
调试C++异常的两种办法:1) 直接获取异常的相关调用函数,在相应函数处设置断点。2) 利用gdb的catch throw/catch。(程序执行后,方有效)如何获取C++调用函数信息?写一个简单C++程序,让程序因异常而终止,bt查看调用栈,即可知道异常相关函数。转载 2014-08-16 22:37:57 · 20046 阅读 · 0 评论 -
Linux debug tools
1. gdb attach [pid] -- debug a running process2. valgrind-- a suite of tools for debugging and profiling programsVery powerful tool to debug linux program,just for x86 platform3. strace -t转载 2014-08-16 19:11:56 · 581 阅读 · 0 评论 -
Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?刚开始看到题目简单的写了个递归,提交超时。后来又仔细推演原创 2014-03-12 11:15:52 · 582 阅读 · 0 评论 -
Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.刚看到原创 2014-03-12 12:33:16 · 547 阅读 · 0 评论 -
Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] ha原创 2014-03-12 10:46:28 · 3896 阅读 · 0 评论 -
二叉树求深度的实现
前天面试的时候被问到一个求二叉树深度的问题,结果最后没想出来,悲剧了。后来上网一查原来递归超简单,真是鄙视递归害死人啊,至少有时候解决问题比追求优雅效率之类的更重要。以后绝对不能看不起递归算法了。下面自己简单的实现了一下,并且连非递归也一并实现了。递归算法如下,其实递归才是真的简洁优雅。int getDepth(struct BiTree *root){ int leftD = 0原创 2013-08-23 10:10:49 · 820 阅读 · 0 评论 -
二分查找的实现
templateint BiSearch(T Array[], int size, T value){ int mid, front, end; front = 0; end = size-1; while (front < end) { mid = (front + end)/2; if (Array[mid] == value) return mid; els原创 2013-08-23 10:24:32 · 528 阅读 · 0 评论 -
C++ public class
class默认是全部公有的,访问控制字段只对继承时有效,通常访问控制字段只是针对类内容的成员,居然不知道这么弱的问题!!!原创 2013-08-28 10:53:28 · 1993 阅读 · 0 评论 -
左值和右值引用的一个例子
http://msdn.microsoft.com/en-us//library/vstudio/dd293668.aspxThe compiler treats a named rvalue reference as an lvalue and an unnamed rvalue reference as an rvalue.When you write a function t转载 2013-09-17 13:44:16 · 686 阅读 · 0 评论 -
C++ 0x 之左值与右值、右值引用、移动语义、传导模板
http://blog.csdn.net/hikaliv/article/details/4541429文 / 李博(光宇广贞) 左值与右值 左值与右值的概念要追溯到 C 语言,由 C++ 语言继承了上来。C++ 03 3.10/1 如是说:“Every expression is either an lvalue or an rvalue转载 2013-09-17 12:56:20 · 746 阅读 · 0 评论 -
shared_from_this
看陈硕的muduo代码库的时候,里面的TcpConnection用到了enable_shared_from_this这个基类,今天查了一下,这个基类提供了一个shared_from_this()公用方法可以让子类内部获取到shared_ptr的对象,用来用在类实现过程中需要传递自身指针的地方。有几个点需要注意一下:1.虽然enable_shared_from_this是基类,但它确实在shar原创 2013-10-09 17:17:53 · 8176 阅读 · 0 评论 -
关于成员函数指针和普通函数指针的转换
http://bbs.csdn.net/topics/10251675查看九楼zdhe的回复。a function call like followingp->func(100); // it will return nothing.in C++ will be compiled to like following push 64h //push原创 2013-09-24 15:16:44 · 2012 阅读 · 0 评论 -
一个C++实现的rollback小技巧
今天看刘未鹏的一篇介绍现在C++的文章时,学到了一个C++中实现rollback的技巧。先定义一个rollback管理类:class ScopeGuard{public: explicit ScopeGuard(std::function onExitScope) : onExitScope_(onExitScope), dismissed_(false)原创 2013-10-15 16:06:38 · 1518 阅读 · 0 评论 -
C/C++浮点数在内存中的存储方式
http://www.cnblogs.com/dolphin0520/archive/2011/10/02/2198280.htmlC/C++浮点数在内存中的存储方式 任何数据在内存中都是以二进制的形式存储的,例如一个short型数据1156,其二进制表示形式为00000100 10000100。则在Intel CPU架构的系统中,存放方式为 10000100(低转载 2013-11-04 16:42:09 · 522 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.相比第一次写的代码,这次的看起来有点代码之原创 2014-03-11 13:08:21 · 614 阅读 · 0 评论 -
[LeetCode]Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges原创 2014-09-25 23:29:18 · 2837 阅读 · 1 评论