摘要: 题目是这样的:设计讲数组A[0...n-1]中所有奇数移到所有偶数之前的算法,要求不另增加储存空间,且时间复杂度为O(n).以往我用常规的思维会这样设计,设两个整型变量i,j, i指向A[0]所在位置, j指向A[n-1]所在位置. 然后对数组进行遍历,如果发现是奇数,则将A[i]和当前数调换, 如果是偶数,则将A[j]和当前数调换,直到遍历结束.但现在用递归思想重新思考这道题, 设f(n)为奇偶... 阅读全文
posted @ 2007-01-09 20:58 浅蓝の天 阅读(471) 评论(1) 推荐(0) 编辑
摘要: (define (for-each proc items) (cond ((not (null? items)) (proc (car items)) (for-each proc (cdr items))))) 阅读全文
posted @ 2007-01-09 20:14 浅蓝の天 阅读(165) 评论(0) 推荐(0) 编辑
摘要: (define (square-list3 items) (define (append list1 list2) (cond ((null? list1) list2) (else (cons (car list1) (append (cdr list1) list2))))) (define (iter thing answer) (cond ((null? thing) answer) (e... 阅读全文
posted @ 2007-01-09 20:03 浅蓝の天 阅读(211) 评论(0) 推荐(0) 编辑
摘要: (define (last-pair items) (cond ((or (null? items) (null? (cdr items))) items) (else (last-pair (cdr items)))))(define (reverse items) (cond ((null? items) items) (else (append (reverse (cdr items)) (... 阅读全文
posted @ 2007-01-09 19:31 浅蓝の天 阅读(186) 评论(0) 推荐(0) 编辑
摘要: (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y))))(define (make-interval a b) (cons a b))(define (lower-bound x) (cond ((> (car x) (... 阅读全文
posted @ 2007-01-08 23:31 浅蓝の天 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 2.13 请证明,在误差很小的百分数条件下,存在着一个简单公式,利用它可以从两个被乘区间的误差算出乘积的百分数误差值.你可以假定所有的数为正,以简化这一问题.证明: 设c1,c2,p1,p2均大于0, 其中c1,c2为中心点, p1, p2为误差百分值, 那么两个区间分别为(c1 - c1p1, c1 + c1p1) , (c2 - c2p2, c2 + c2p2)因为c1 > 0,c2 &... 阅读全文
posted @ 2007-01-08 23:10 浅蓝の天 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 证明:设求区间的宽度函数为h(x)先证区间的加法: 设任意两区间为(a, b) (c, d),那么(a, b) + (c, d) = ( min(a, b) + min(c, d),max(a, b) + max(c, d) )那么h((a, b) + (c, d)) = (max(a, b) + max(c, d) - min(a, b)- min(c, d) ) / 2 = ( max(a, ... 阅读全文
posted @ 2007-01-08 17:26 浅蓝の天 阅读(183) 评论(0) 推荐(0) 编辑
摘要: (define (average-damp f) (lambda (x) (/ (+ (f x) x) 2)))(define (fixed-point f guess) (define (closed-enough? v1 v2) (< (abs (- v1 v2)) 0.000000000001)) (let ((next (f guess))) (cond ((closed-enoug... 阅读全文
posted @ 2007-01-06 23:30 浅蓝の天 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 可推导出 tanx的公式为 tanx = Fn(k)(x) / x其中Fn(k)(x) = x^2 / (2(n-k) - Fn(k - 1)(x))(define (tan-cf x k) (define (tan-helper k N) (cond ((= k 0) 0) (else (/ (square x) (- (+ (* 2 (- N k)) 1) (tan-helper (- k ... 阅读全文
posted @ 2007-01-05 22:22 浅蓝の天 阅读(144) 评论(0) 推荐(0) 编辑
摘要: (define (cont-frac n d k) (define (compute m) (cond ((= m k) 0) (else (/ (n m) (+ (d m) (compute (+ m 1))))))) (compute 0))(define (f i) (define (g k) (+ 1 (* k 3))) (define (h m) (cond ((> (g m) i... 阅读全文
posted @ 2007-01-04 22:11 浅蓝の天 阅读(134) 评论(0) 推荐(0) 编辑