- 博客(86)
- 收藏
- 关注

原创 排序算法实现
//version 1.03#include#include#includeusing namespace std;void swap(int &a, int &b){ int temp = a; a = b; b =temp;}template T myMax(T a, T b){ return a >= b ? a : b;}//////////////
2014-07-21 20:38:26
542
原创 leetcode 4sum
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Eleme
2014-08-10 13:13:23
678
原创 leetcode 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa
2014-08-10 13:10:58
511
原创 leetcode Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
2014-08-10 13:08:46
611
原创 leetcode Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, w
2014-08-10 13:07:12
530
原创 leetcode 3Sum
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,
2014-08-10 13:02:54
564
原创 c++11新性能测试4
#include#include#include using namespace std;vector> func(){ vector> vv; int a[] = {1,2,3,4,5}; int b[] = {6,2,3,4,5}; int c[] = {5,2,2,4,5}; vv.push_back(vector(a, a+5));
2014-08-10 13:00:00
746
原创 c++11新性能测试3
#include#includeusing namespace std;using namespace std::placeholders;//函数int half(int x) {return x/2;}//仿函数struct third_t { int operator()(int x) {return x/3;}};//结构体struct MyValue {
2014-08-09 21:51:53
534
原创 c++11新性能测试2
#include #include #include using namespace std;struct C {int* data;};struct D {int a; int b;};int main(){ shared_ptr p1; shared_ptr p2(nullptr); shared_ptr p3(new int); shared_p
2014-08-09 19:36:37
598
原创 C++11新性能测试
// shared_ptr::operator*#include #include #include using namespace std;int main () { int a[] = {1,2,3,4,5}; int b[] = {2,3,4,5,6}; int c[] = {3,4,5,6,7}; vector> vv; vv.reserve(10);
2014-08-09 19:33:36
652
原创 hash_map 和 hash_mutilmap
class hash_map{private: typedef hashtable,_Key,_HashFcn, _Select1st >,_EqualKey,_Alloc> _Ht; _Ht _M_ht; //可见hashmap内部的是使用hashtable实现的public: typedef typename _Ht::key_typ
2014-07-30 23:29:58
1191
原创 STL hashtable 源码分析
在stl_hash_fun.h中,定义如下inline size_t __stl_hash_string(const char* __s){ unsigned long __h = 0; for ( ; *__s; ++__s) __h = 5*__h + *__s; return size_t(__h);}__STL_TEMPLATE_NULL struct h
2014-07-30 23:05:28
947
转载 解题笔记(37)——Catalan数计算及应用
问题描述:卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。输入一个整数n,计算h(n)。其递归式如下:h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2,h(0) = h(1) = 1) 该递推关系的解为:h(n)=C(2n,n)/(n+1) (n=1,2,3,...) 思路:直接根据
2013-03-28 23:24:15
833
转载 给定一个入栈序列,求所有可能的出栈序列
网上有很多解法,但个人感觉不够清晰。下面本人献丑来写下自己的解法。力求简明易懂。首先这是个卡特兰数,学过组合数学的同学都知道。没学过的可以看下下面这个例子。有2n个人排成一队进入剧场。入场费5元。其中只有n个人有一张5元钞票,另外n人只有10元钞票,剧院无其它钞票可找零,问有多少中方法使得只要有10元的人买票,售票处就有5元的钞票找零?(将持5元者到达视作将5元入栈,持10元者到达视作使栈
2013-03-28 22:49:16
1365
原创 内存小实验
#includeint main(){ int a[2][2]={{1,2},{3,4}}; int *p; p = a; printf("%d,%d,%d,%d!\n",*p,*(p++),*(p++),*(p++)); printf("%d\n",a); return 0;}可以看到二维数组在内存中的存储和一维数组没
2012-09-11 15:20:08
1412
原创 函数指针
///函数指针的小实验///2012-9-11///知道函数地址,如何调用#includetypedef int(*pFun)(void);int print(void){ printf("Hello,world!\n");}int main(){ int funAddress; pFun pFunTemp; funAddress = p
2012-09-11 10:17:00
461
原创 linux下的文件和设备
linux环境下有一句话:一切都是文件。确实很有道理,基本的操作方式:open,read,write,close对开发者来说几乎没有什么差别。但是,普通文件和驱动文件还是有些许不同。普通文件是有缓冲的,当我们写文件时,会先写入缓冲区。当出现以下情况时会写入文件中1.缓冲区慢 2.ffush刷新缓冲区 3.回车换行新手开始写程序时,向文件里面写入数据,但是打开文件时显示为空。就是这个
2012-09-03 09:52:10
486
转载 虚拟内存管理总结
操作系统为每一个进程维护着一个虚拟的地址空间,这个地址空间的大小通常取决于系统的地址线数目,比如在32位系统中,虚拟地址空间的返回就是0×00000000~0xFFFFFFFF,大小共4G。通常操作系统会划分出一部分来专门供内核使用,而不允许用户进程直接访问。Linux内核占用4G中高地址的1G,即0XC0000000~0XFFFFFFFF,windows内核通常占用高地址的2G空间,但也可配置成
2011-11-22 13:35:47
734
原创 c# 委托理解
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 委托深度理解{ /// /// 比如孩子想买个东西,但是她很懒,所以就想让爸爸妈妈帮她买, /// 这就是委托。委托是类型安全的,和指针类似但是直接操作内存是很危险 //
2011-11-07 11:13:20
526
原创 c# 进阶
http://book.51cto.com/art/201109/292328.htm http://hi.baidu.com/ycdoit/blog/category/c%2B%2B%B1%EA%D7%BC%C4%A3%B0%E5%BF%E2很好的资料有些时候,本地资源会占用大量的内存, 而托管资源只占用一点资源,那么GC很难估计是否应该对这个资源进行垃圾回收,因为很难满
2011-11-05 09:41:52
588
转载 IEnumerable和IEnumerator有什么区别?
问题的提出:见(C#高级编程P127)public interface IEnumerable{ IEnumerator GetEnumerator();} public interface IEnumerator{ bool MoveNext(); void Reset(); Object Current { get; }
2011-11-04 11:51:09
579
转载 浅谈C#中的枚举
枚举类型是一种的值类型,它用于声明一组命名的常数。 (1)枚举的声明:枚举声明用于声明新的枚举类型。 访问修辞符 enum 枚举名:基础类型 { 枚举成员 } 基础类型必须能够表示该枚举中定义的所有枚举数值。枚举声明可以显式地声明 byte、sbyte、short、ushort、int、uint、long 或 ulong 类型作为对
2011-11-04 10:21:10
375
转载 用代码验证阿里巴巴的一道关于男女比例的面试题
今天在优快云首页看了一篇博客《阿里巴巴的面试》。其中有一个问题,比较有意思:说澳大利亚的父母喜欢女孩,如果生出来的第一个女孩,就不再生了,如果是男孩就继续生,直到生到第一个女孩为止,问若干年后,男女的比例是多少?刚看到问题是的思维逻辑:用递推法,假设一对夫妻,生了个女儿,就不再要了;另外一对夫妻,生了个儿子,再要一个,是女儿,然后也就不要了。第一感觉,应该是女的比男的多。然后思考如何
2011-11-02 14:10:19
818
原创 C# 双向链表
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace csharp链表{ class Program { public class Node { private Node child;
2011-11-01 09:39:10
713
转载 求1+2+…+n,要求不能使用乘除法、for、while、if、else...
题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。其实会有很多种解法,但是下面给出了一个简单的代码-----巧用递归算法。view plainprint?#include #include #include int add_
2011-10-31 11:49:34
731
转载 一个简单的C#多线程间同步的例子
using System;using System.Collections;using System.Collections.Generic;using System.Threading;////// 在开发中经常会遇到线程的例子,如果某个后台操作比较费时间,我们就可以启动一个线程去执行那个费时的操作,同时程序继续执行。在某些情况下可能会出现多个线程的同步协同的问题,下面的例子就展示了
2011-10-24 10:14:23
467
转载 IDictionary 泛型接口
using System;using System.Collections.Generic;public class Example{ public static void Main() { // Create a new dictionary of strings, with string keys, // and access it t
2011-10-23 22:12:12
543
转载 堆栈的实现
#include#include#include#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0#define OVERFLOW -2typedef int status;typedef struct{ int *base; int *top; int stac
2011-10-20 14:37:46
477
转载 c#中的非托管资源释放 (Finalize和Dispose)
在了解Finalize和Dispose之前,我们需要了解两个概念,一个是托管资源,一个非委托资源。a.其中托管资源一般是指被CLR控制的内存资源,这些资源的管理可以由CLR来控制,例如程序中分配的对象,作用域内的变量等。b.而非托管资源是CLR不能控制或者管理的部分,这些资源有很多,比如文件流,数据库的连接,系统的窗口句柄,打印机资源等等……这些资源一般情况下不存在于Heap(内存中用于存
2011-10-20 08:24:18
1106
原创 单线性链表
#include#includetypedef struct LNode{ int StudentNo; int Math; struct LNode *next;}LNode;LNode *inint(void);void display(LNode *L);int GetLength(LNode *L);LNode *AddItm(LNode *L,int num,in
2011-10-19 23:16:23
714
原创 c语言深入理解<4>
/**********************************8#include #include int main(void){ int i; int *pn=(int *)calloc(10,sizeof(int)); //calloc 的作用是分配并初
2011-10-18 11:22:44
870
原创 c语言深入理解<3>
/***********************************//Exanple 1#includevoid display(char *);//指针做形参void main()//如果没有void,默认为int类型,可能出现错误{ char s[]="ab
2011-10-18 10:08:30
789
原创 c语言深入理解<2>
#include#define Max(a,b) ((a)>(b)?(a):(b))void main(){ int a[3]={2,3,1},i=1,max=a[0]; while(i<3) { max=Max(max,a[i++]); printf
2011-10-17 15:27:06
388
原创 c语言深入理解<1>static理解
Example 1:#include void fn();static int n; //定义静态全局变量void main(){ n=20; cout<<n<<endl; fn();}void fn(){ n++; cout<<n<<endl;
2011-10-17 10:06:25
560
原创 算法:用数组求两个字符串最长的公共子串
using System;using System.Collections;namespace 数据结构_数组{ class Program { public static Int32 MaxLen; public stat
2011-10-15 11:13:07
1768
原创 汉诺塔算法
using System;namespace 汉诺塔算法{ class Program { static void Main(string[] args) { Console.WriteLine("盘数
2011-10-14 15:59:02
1453
转载 BF算法与KMP算法
using System;namespace kmp{ /// /// Summary description for Class1. /// class Class1 { /// /// The
2011-10-14 15:25:25
681
原创 CLR_VIA_C# 数组
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;namespace CLR_VIA_C__数组{
2011-10-14 09:58:49
784
转载 二叉树
#include#includetypedef struct Node{ char data; struct Node *lchild; struct Node *rchild;}BiTreeNode;BiTreeNode *CreatBiTree(BiTreeN
2011-10-13 21:40:13
428
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人