06 2013 档案
.NET设计模式系列文章 from TerryLee
摘要:http://www.cnblogs.com/Terrylee/archive/2006/07/17/334911.html最初写探索设计模式系列的时候,我只是想把它作为自己学习设计模式的读书笔记来写,可是写到今天,设计模式带给我的震撼,以及许多初学者朋友的热心支持,让我下定决心要把这个系列写完写好,那怕花上再多的时间也无所谓。本部分内容不断更新中。目录计划:第Ⅰ部分开篇开篇第Ⅱ部分创建型模式篇第1章单件模式(Single Pattern)第2章抽象工厂模式(Abstract Factory)第3章建造者模式(Builder Pattern)第4章工厂方法(Factory Method)第5章 阅读全文
posted @ 2013-06-17 15:57 Alan Yang 阅读(235) 评论(0) 推荐(0) 编辑
Sort
摘要:--heap sort . O(n*logn). auxiliary space O(1). Unstable sorting. class ArraySort { static void Main(string[] args) { //give up 0 index. get/set from 1 so that getting right index when do j=2*i. int[] a = new int[11] {0,5,77,1,61,11,59,15,48,47,25 }; ... 阅读全文
posted @ 2013-06-16 17:43 Alan Yang 阅读(177) 评论(0) 推荐(0) 编辑
不要用把无序GUID既作为主键又作为聚集索引【转】
摘要:http://www.cnblogs.com/zhouruifu/archive/2012/04/18/2454088.html我一直想当然的认为用GUID做主键没什么大不了,不就是比int多了12位而已吗?而且现在都是SQL Server 2008, 2012时代了,应该更不是问题了吧?而且微软很多项目也是用GUID做主键啊?Sharepoint, ASP.NET SQL Server Membership Provider默认的表等等。而且还有许多而且......果真这样吗?直到我读了这两篇文章后GUIDs as PRIMARY KEYs and/or the clustering key 阅读全文
posted @ 2013-06-15 10:55 Alan Yang 阅读(417) 评论(0) 推荐(0) 编辑
k largest(or smallest) elements in an array | added Min Heap method
摘要:http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/k largest(or smallest) elements in an arrayMarch 1, 2010Question:Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.For example, if given array is [1, 23, 12, 9, 30, 2, 5 阅读全文
posted @ 2013-06-14 21:56 Alan Yang 阅读(340) 评论(0) 推荐(0) 编辑
将递归转化成迭代的通用技术
摘要:http://blog.csdn.net/whinah/article/details/6419680从理论上讲,只要允许使用栈,所有的递归程序都可以转化成迭代。但是并非所有递归都必须用栈,不用堆栈也可以转化成迭代的,大致有两类尾递归:可以通过简单的变换,让递归作为最后一条语句,并且仅此一个递归调用。// recursiveint fac1(int n) { if (n <= 0) return 1; return n * fac1(n-1);}// iterativeint fac2(int n) { int i = 0, y = 1; for (; i <= n; ... 阅读全文
posted @ 2013-06-13 17:08 Alan Yang 阅读(915) 评论(0) 推荐(1) 编辑
A child is running up a staircase with N steps, and can hop either 1 step,2steps,3 steps at a time. Count how many possible ways the child can run up
摘要:A child is running up a staircase with N steps, and can hop either 1 step,2steps,3 steps at a time. Count how many possible ways the child can run up the stairs. class Upstaircase { static void Main(string[] args) { /* Enter your code here. Read input from STDIN. Print ou... 阅读全文
posted @ 2013-06-13 00:54 Alan Yang 阅读(357) 评论(0) 推荐(0) 编辑
Find whether an array is subset of another array
摘要:http://www.geeksforgeeks.org/find-whether-an-array-is-subset-of-another-array-set-1/Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order.Examples:Input: arr1[] = {11, 1, 13, 21, 3, 7}, arr2[] = {11, 3, 7, 1}Output: 阅读全文
posted @ 2013-06-09 16:34 Alan Yang 阅读(309) 评论(0) 推荐(0) 编辑
Are C# delegates thread-safe?
摘要:http://stackoverflow.com/questions/6349125/are-c-sharp-delegates-thread-safeRegarding the invocation of the delegate the answer is yes.Invoking a delegate is thread-safe because delegates are immutable. However, you must make sure that a delegate exists first. This check may require some synchroniza 阅读全文
posted @ 2013-06-07 17:25 Alan Yang 阅读(266) 评论(0) 推荐(0) 编辑
print all permutations of a given string
摘要:http://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation.So 阅读全文
posted @ 2013-06-07 16:40 Alan Yang 阅读(473) 评论(0) 推荐(0) 编辑
Write your own atoi()
摘要:heatoi()function takes a string (which represents an integer) as an argument and returns its value.Following is a simple implementation. We initialize result as 0. We start from the first character and update result for every character.// A simple C++ program for implementation of atoi#include <s 阅读全文
posted @ 2013-06-07 14:38 Alan Yang 阅读(169) 评论(0) 推荐(0) 编辑