# 《Two Dozen Short Lessons in Haskell》（二十二）递归

### 第二十二章 Recursion

1 Which of the following defines a function that delivers the same results as the intrinsic function reverse?

a rev(x : xs) = xs ++ [x]

rev [ ] = [ ]

b rev(xs : x) = x : xs

rev [ ] = [ ]

c rev(x : xs) = rev xs ++ [x]

rev [ ] = [ ]

d none of the above

2 Which of the following defines a function that would rearrange a sequence of numbers to put it in decreasing
numeric order?

a sortDecreasing = quickSortWith (>)

b sortDecreasing = quickSortWith (>) [18.01528974, 1.89533e+25, 1.05522e-24, 27.0]

c sortDecreasing = quickSortWith (>) numbers

d all of the above

3 The following function

HASKELL DEFINITION • sorta(x : xs) = insert x (sorta xs)

HASKELL DEFINITION • sorta [ ] = [ ]

HASKELL DEFINITION • insert a (x : xs)

HASKELL DEFINITION •     | a <= x = [a, x] ++ xs

HASKELL DEFINITION •     | otherwise = [x] ++ (insert a xs)

HASKELL DEFINITION • insert a [ ] = [a]

a delivers the same results as quicksort

b delivers the same results as quicksortWith (<)

c both of the above

d neither of the above

=============================

=============================

1 c

2 a

3 c

sorta就是插入排序

quicksort默认是从小到大排序

posted @ 2013-06-18 22:31  申龙斌的程序人生  阅读(775)  评论(0编辑  收藏  举报