# 编程范式与语言

python对象式实现
class Bisection (FindMinima):
def algorithm(self,line):
return (5.5,6.6)
def algorithm(self,line):
return (3.3,4.4)
class MinimaSolver: # context class
strategy=''
def __init__ (self,strategy):
self.strategy=strategy
def minima(self,line):
return self.strategy.algorithm(line)
def changeAlgorithm(self,newAlgorithm):
self.strategy = newAlgorithm
def test():
print solver.minima((5.5,5.5))
solver.changeAlgorithm(Bisection())
print solver.minima((5.5,5.5))

python函数式实现
def bisection(line):
return 5.5, 6.6
return 3.3, 4.4
def test():
print solver((5.5,5.5))
solver = bisection
print solver((5.5,5.5))


C过程式实现
void quickSort(int* arr,int startPos, int endPos)
{
int i,j;
int key;
key=arr[startPos];
i=startPos;
j=endPos;
while(i<j)
{
while(arr[j]>=key && i<j)--j;
arr[i]=arr[j];
while(arr[i]<=key && i<j)++i;
arr[j]=arr[i];
}
arr[i]=key;
if(i-1>startPos)
quickSort(arr,startPos,i-1);
if(endPos>i+1)
quickSort(arr,i+1,endPos);
} 

erlang函数式实现
qsort([]) -> [];

qsort([H|T])->
qsort([LO || LO <- T, LO < H]) ++ [H] ++ qsort([HI || HI <- T, HI >= H]).



1. 《冒号课堂》
2. 《程序设计语言--实践之路》第三版

-- EOF--
posted @ 2015-06-08 17:48  wahaha02  阅读(2028)  评论(1编辑  收藏