1.2.4.10. 练习
练习:斐波那契数列
写一个函数来展示斐波那契数列的前n个项目,定义如下:
- u_0 = 1; u_1 = 1
- u_(n+2) = u_(n+1) + u_n
练习:快速排序
实现快速排序算法,定义来自wikipedia:
function quicksort(array)
var list less, greater if length(array) < 2
return array
select and remove a pivot value pivot from array for each x in array
if x < pivot + 1 then append x to less else append x to greater
return concatenate(quicksort(less), pivot, quicksort(greater))