泛型编程,英文叫做Generic programming可以理解为,具有通用意义的、普适性的,编程。比如,你要实现一个函数去比较两个数值的大小,数值可能是int或者string。初次尝试,我们直观会想到定义多个重载函数。如下:int compare(const string &v1, const s...
分类:
编程语言 时间:
2015-03-30 16:15:55
阅读次数:
141
泛型编程就是以独立于任何特定类型的方式编写代码,而模板是泛型编程的基础。
(1)定义函数模板(function template)
函数模板是一个独立于类型的函数,可以产生函数的特定类型版本。
// implement strcmp-like generic compare function
template
int compare(const T &v1, const T &...
分类:
编程语言 时间:
2015-03-30 14:43:04
阅读次数:
296
练习4-3原文Exercise 4.3. Rewrite eval so that the dispatch is done in data-directed style. Compare this with the datadirected differentiation procedure of exercise 2.73. (You may use the car of a compound...
分类:
其他好文 时间:
2015-03-30 09:33:38
阅读次数:
167
Compare Version Numbers
Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.
You may assume that the version...
分类:
其他好文 时间:
2015-03-29 13:42:43
阅读次数:
130
一般情况下,自己动手写一个简单排序程序还是没有问题的,但是你能保证写出来的排序程序的时间复杂度吗?你能保证程序的正确性吗,鲁棒性呢,还有程序结构的清晰性,可维护性.......综上所述,学习一下排序接口来实现对复杂对象的排序还是很有必要的。Java中有两个用来实现排序的接口Comparator和Comparable接口,本人比较喜欢使用java的Comparator接口,在程序里实现Comparator接口里的compare(Object o1,Object o2)方法,然后在程序中通过调用Arrays.s...
分类:
编程语言 时间:
2015-03-29 10:48:44
阅读次数:
184
Problem Description
Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.
The workers will compare their rewards ,and some one m...
分类:
编程语言 时间:
2015-03-28 11:36:19
阅读次数:
213
edge = [[1,2,1],[1,2,3],[1,3,2],[2,3,1],[2,4,4],[3,4,2]]
#这是用边集合表示的图
s = [[]]
n = 4
for i in range(n):
s.append([i+1])
#print s
#compare方法是为了对边排序写的,作为参数传入sort,就可以排序了
def compare(a,b):
if(a[2...
分类:
编程语言 时间:
2015-03-27 22:26:43
阅读次数:
242
题目链接:compare-version-numbers
import java.util.ArrayList;
import java.util.List;
/**
*
Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < vers...
分类:
其他好文 时间:
2015-03-21 09:53:42
阅读次数:
213
Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1 v2) return 1; } return 0; }}
分类:
其他好文 时间:
2015-03-20 23:33:07
阅读次数:
140
转自:http://www.myext.cn/other/a_30922.html比较日期大小是任何编程语言都会经常遇到的问题,再iOS编程中,通常用NSDate对象来存储一个时间(包括日期和时间、时区),而且 NSDate类提供了compare方法来进行时间的比较,但有时不想那么精确的知道两个日期...
分类:
移动开发 时间:
2015-03-20 18:32:07
阅读次数:
136