scheme sort list diffent criteria

本小妞迷上赌 提交于 2019-12-02 08:38:44

As far as I can tell, your ordered criteria are the order in which to sort. If this is the case, then the following program should perform that sorting.

(define (strange-sort quadruples)
  (define (a2 quad)
    (cadr quad))
  (define (a3 quad)
    (caddr quad))
  (define (a4 quad)
    (cadddr quad))
  (sort quadruples
        (lambda (x y)
          (cond ((< (a2 x) (a2 y))
                 #t)
                ((> (a2 x) (a2 y))
                 #f)
                (else
                 (cond ((< (- (a3 x) (a4 x))
                           (- (a3 y) (a4 y)))
                        #t)
                       ((> (- (a3 x) (a4 x))
                           (- (a3 y) (a4 y)))
                        #f)
                       (else
                        (cond ((< (a3 x) (a3 y))
                               #t)
                              (else #f)))))))))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!