用形式化的容器来跑归并排序

(mymachine   (

(defmacro  demoinside  (expr)

(print  expr)

)

(defmacro  mymachineinside  (exprs)

`(if  ,(eq  exprs  nil) 

      nil

     (progn

          (demoinside ,(car  exprs)) 

         (mymachineinside  ,(cdr  exprs) )

      )

)

)

 

(mymachineinside   (

(defmacro  demo  (expr)

(print  expr)

)

(defmacro  mymachine  (exprs)

`(if  ,(eq  exprs  nil) 

      nil

     (progn

          (demo ,(car  exprs)) 

         (mymachine  ,(cdr  exprs) )

      )

)

)

(defun  mycons ( x  y)

(lambda (p ) (funcall p  x  y) )

)

 

(defun  mycar  (n)

(funcall  n   (lambda( x y)  x) )

)

 

(defun  mycdr  (n)

(funcall  n   (lambda( x y)  y) )

)

 

(defun  mycadr  (n)

(mycar  (mycdr  n) )

)

 

(defun printlst (n)

(if  (eq   n  nil)

        nil

      (progn

          (print  (mycar  n) )

          (printlst (mycdr n) )

       )

)

)

 

 

(defun  emerge  (x  y)

(if (eq  x  nil)

      y 

   (if  (eq  y  nil )

         x 

      (if  (>  (mycar  x )  (mycar  y) )

             (mycons  (mycar  y)   (emerge  x  (mycdr y) ) ) 

            (mycons  (mycar  x )  ( emerge  (mycdr x)  y ) )          

      )

   )

)

)

 

(defun  ptr  ( x  num )

(if  (eq  num  0)

    x

   (ptr  (mycdr  x )   (-  num  1 ) )

)

)

 

(defun  myget  (x    count )

(if  (eq  count  0)

         nil

     (mycons  (mycar  x)  (myget (mycdr x ) (-  count  1) ) )

)

)

 

(defun divi  (x  num )

(if  (eq  num  2)

         (if  (>  (mycar  x )  (mycadr  x) )

            (mycons  (mycadr  x ) (mycons (mycar  x) nil) )

            x

          )

   (emerge  (divi  (myget (ptr  x  0 ) (/ num  2) )  (/ num  2) ) 

              (divi  (myget  (ptr  x  (/  num  2) ) (/ num  2 ) ) (/  num  2) )  )

)

)

 

 

(setq  y (mycons 23 (mycons 345 nil) )  )

(printlst (divi  y  2) )

(setq  y (mycons 345 (mycons 23  nil) )  )

(printlst (divi  y  2))

 

(setq  y (mycons 345  (mycons 23 (mycons 10  (mycons 89 (mycons 34 (mycons 2 (mycons 77 

 

(mycons 864 nil)))))))))

(printlst (divi  y  8) )

(setq  z   (mycons 23 (mycons 34 (mycons 11 (mycons 98 (mycons 456 (mycons 875 (mycons 76 

 

(mycons 21 nil)))))))))

(printlst (divi  z  8) )

 

))

))

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值