随笔分类 -  Algorithms

摘要:Week1 Job Interview QuestionSocial network connectivity.Given a social network containingNmembers and a log file containingMtimestamps at which times pairs of members formed friendships, design an algorithm to determine the earliest time at which all members are connected (i.e., every member is a fr 阅读全文
posted @ 2014-02-18 22:45 理想空间 阅读(1669) 评论(0) 推荐(0)
摘要:在C++中,我们经常使用STL,那个在那些我们常用的数据结构vector,list的背后,又是如何实现的呢?特别是当我们使用iterator对容器进行遍历的时候,我们也能够想整数一样进行 ++ 运算。下面通过一个例子来建立一个slist,使得它能够通过iterator进行访问。我们要实现的功能是:建立一个list存储任意个数,然后输入一个数,通过find函数查找是否在list中存在。所以我们首先要编写一个find函数,find函数的要求是能够操作多种容器,能够查找多种数据类型(int,double),所以应该建立一个模版函数。(实际在STL中,这类函数应该叫算法,它通过iterator对容器进 阅读全文
posted @ 2013-01-17 22:03 理想空间 阅读(2139) 评论(0) 推荐(0)
摘要:C++ STL中的Iterator遍历容器的时候,无需知道具体的是哪个容器,只用传入地址即可。容器可以使用数组来模拟。代码如下:/************************************************************************//* implement of find function without stl *//************************************************************************/#include <iost... 阅读全文
posted @ 2013-01-16 17:30 理想空间 阅读(407) 评论(0) 推荐(0)
摘要:归并排序 详细分析 阅读全文
posted @ 2013-01-15 00:11 理想空间 阅读(16877) 评论(4) 推荐(0)
摘要:Consider the problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in the an (n+1) -element array C. State the problem formally and write pseudocode for adding the two integers.[Pseudocode]Adding-A-B(A,B,C) .. 阅读全文
posted @ 2013-01-13 17:07 理想空间 阅读(483) 评论(0) 推荐(0)