马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- ;;测试程序
- (defun c:test (/ coord tt)
- (setq coord
- '(
- (1 (1 . 2) 3 ("kkj" 4) (3 0))
- (1 (1 . 4) 1 ("skj" 45) (2 3))
- (1 (1 . 2) 3 ("Aej" 45) (7 1))
- (1 (2 . 3) 2 ("ser" 4) (9 2))
- (2 (6 . 2) 2 ("Serj" 9) (1 4))
- (3 (3 . 5) 1 ("kkjsd" 35) (7 6))
- (2 (4 . 7) 2 ("Akjdd" 3) (5 4))
- (3 (3 . 3) 3 ("sekj" 446) (3 4))
- (2 (2 . 2) 2 ("serj" 9) (1 4))
- (1 (8 . 2) 2 ("wggj" 46) (2 4))
- (1 (1 . 4) 1 ("kkj" 9) (4 4))
- (3 (3 . 3) 3 ("sekj" 446) (3 4))
- (1 (8 . 2) 2 ("wggj" 46) (2 4))
- )
- )
-
- ;;表第一项为要排序的依据,注意后面的括号没有,第二项即为后括号的个数,第三项为按升还是降排序
- (setq tt '(("(nth 0 (nth 3 " 2 ">")
- ("(nth 0" 1 "<")
- ("(car (nth 1 " 2 "<")
- ("(nth 1 (nth 4 " 2 ">")
- ("(nth 1 (nth 3" 2 ">")
- )
- )
- (order coord tt)
- )
- ;;;主程序
- (defun order (coord_list tj / coord_ord coord_I i j k n tj_ tj_c tj_1
- tj_2)
- (setq n (length coord_list))
- (setq k (length tj))
- (setq tj_ "(cond ((")
- (setq tj_1 (nth 0 (nth 0 tj)))
- (setq tj_2 tj_1)
- (setq tj_1 (strcat tj_1 " p1"))
- (setq tj_2 (strcat tj_2 " p2"))
- (repeat (nth 1 (nth 0 tj))
- (setq tj_1 (strcat tj_1 ")"))
- (setq tj_2 (strcat tj_2 ")"))
- )
- (setq tj_ (strcat tj_ (nth 2 (nth 0 tj)) " " tj_1 tj_2 ") t) "))
- (setq tj_c "((and ")
- (setq i 1)
- (repeat (- k 1)
- (setq tj_c (strcat tj_c "(= " tj_1 " " tj_2 ")"))
- (setq tj_1 (nth 0 (nth i tj)))
- (setq tj_2 tj_1)
- (setq tj_1 (strcat tj_1 " p1"))
- (setq tj_2 (strcat tj_2 " p2"))
- (repeat (nth 1 (nth i tj))
- (setq tj_1 (strcat tj_1 ")"))
- (setq tj_2 (strcat tj_2 ")"))
- )
- (setq tj_ (strcat tj_
- tj_c
- "("
- (nth 2 (nth i tj))
- " "
- tj_1
- tj_2
- ")) t) "
- )
- )
- (setq i (1+ i))
- )
- (setq tj_ (strcat tj_ "(t nil))"))
- (setq
- coord_i
- (vl-sort-i coord_list
- (function (lambda (p1 p2)
- (eval (read tj_))
- )
- )
- )
- )
- (setq j 0)
- (repeat n
- (setq
- coord_ord (append coord_ord
- (list (nth (nth j coord_i) coord_list))
- )
- )
- (setq j (1+ j))
- )
- (setq coord_ord coord_ord)
- )
|