getting the largest number in a list in scheme

前端 未结 6 1717
长发绾君心
长发绾君心 2021-01-23 23:00

I do not understand why my function to get the largest number does not want to work. If I am thinking about this correctly, if the first atom is smaller than the second atom the

6条回答
  •  礼貌的吻别
    2021-01-23 23:41

    (define (max-list-element list)
      (define (aux list actual-max)
        (if (pair? (cdr list))
            (if (>= (car list) actual-max)
                (aux (cdr list) (car list))
                (aux (cdr list) actual-max))
            (if (> (car list) actual-max)
            (car list)
            actual-max)))
      (aux list (car list)))
    

    My implementation.

提交回复
热议问题