【问题标题】:need to combine results of two functions in Scheme with a driver需要将 Scheme 中两个函数的结果与驱动程序结合起来
【发布时间】:2012-09-15 11:54:26
【问题描述】:

我有一个方案分配,其中用户要输入一个数字列表,输出应该是列表中的最大值和最小值。作业说我们可以有两个单独的函数,并将结果与​​驱动程序结合起来,但我不知道该怎么做。这是我目前所拥有的:

(define (findmin l) (if (null? (cdr l)) (car l)
 (if (< (car l) (findmin (cdr l)))(car l)
 (findmin (cdr l)))))

(define (findmax l) (if (null? (cdr l)) (car l)
 (if (> (car l) (findmax (cdr l)))(car l)
 (findmax (cdr l)))))

我似乎无法避免为 findmin 输入一个列表,为 findmax 输入另一个列表。用户应该只需要输入一个列表。

【问题讨论】:

    标签: recursion scheme racket


    【解决方案1】:

    司机:

    (define (min-and-max l) (list (findmin l) (findmax l)))
    

    【讨论】:

      猜你喜欢
      • 2012-09-16
      • 2021-09-28
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多