lisp语言对列表排序问题,使用lisp或vl-lisp求大师指点,谢谢!
filelist‘(“A-S01--1.DWG”"A-S01--12.DWG""A-S01--11.DWG""A-S01--2.DWG""A-S02--1.dwg""B-...
filelist ‘(“A-S01--1.DWG” "A-S01--12.DWG" "A-S01--11.DWG" "A-S01--2.DWG" "A-S02--1.dwg" "B-S01--1.DWG" "B-S02--1.dwg" )《其中字符A,B分别代表某字符串,不对A和B排序。只对S后的排序。》
要求排序后:(“A-S01--1.DWG” "A-S01--2.DWG" "A-S01--11.DWG" "A-S01--12.DWG" "A-S02--1.dwg" "B-S01--1.DWG" "B-S02--1.dwg" ) 展开
要求排序后:(“A-S01--1.DWG” "A-S01--2.DWG" "A-S01--11.DWG" "A-S01--12.DWG" "A-S02--1.dwg" "B-S01--1.DWG" "B-S02--1.dwg" ) 展开
1个回答
展开全部
(defun c:test()
(setq sjb '( "A-S01--12.DWG" "A-S01--1.DWG" "B-S02--1.dwg"
"A-S01--11.DWG" "A-S01--2.DWG" "A-S02--1.dwg"
"B-S01--1.DWG"
)
jgb nil
)
(foreach zb sjb
(setq n1 (vl-string-search "--" zb)
n2 (vl-string-search "." zb)
zfc1 (substr zb 1 n1)
zfc2 (read (substr zb (+ n1 3) (- n2 n1 2)))
pdb (assoc zfc1 jgb)
)
(if pdb
(setq jgb (subst (list zfc1 (cons (list zfc2 zb) (cadr pdb))) pdb jgb))
(setq jgb (cons (list zfc1 (list (list zfc2 zb))) jgb))
)
)
(setq jgb (vl-sort jgb '(lambda(x1 x2) (< (car x1) (car x2))))
fhzb nil
)
(foreach zb jgb
(setq zb2 (vl-sort (cadr zb) '(lambda(x1 x2)(< (car x1) (car x2))))
zb2 (mapcar 'last zb2)
)
(if fhzb
(setq fhzb (append fhzb zb2))
(setq fhzb zb2)
)
)
(princ "\n排序结果:")(princ fhzb)
(princ)
)
测试:
命令: test
排序结果:(A-S01--1.DWG A-S01--2.DWG A-S01--11.DWG A-S01--12.DWG A-S02--1.dwg
B-S01--1.DWG B-S02--1.dwg)
(setq sjb '( "A-S01--12.DWG" "A-S01--1.DWG" "B-S02--1.dwg"
"A-S01--11.DWG" "A-S01--2.DWG" "A-S02--1.dwg"
"B-S01--1.DWG"
)
jgb nil
)
(foreach zb sjb
(setq n1 (vl-string-search "--" zb)
n2 (vl-string-search "." zb)
zfc1 (substr zb 1 n1)
zfc2 (read (substr zb (+ n1 3) (- n2 n1 2)))
pdb (assoc zfc1 jgb)
)
(if pdb
(setq jgb (subst (list zfc1 (cons (list zfc2 zb) (cadr pdb))) pdb jgb))
(setq jgb (cons (list zfc1 (list (list zfc2 zb))) jgb))
)
)
(setq jgb (vl-sort jgb '(lambda(x1 x2) (< (car x1) (car x2))))
fhzb nil
)
(foreach zb jgb
(setq zb2 (vl-sort (cadr zb) '(lambda(x1 x2)(< (car x1) (car x2))))
zb2 (mapcar 'last zb2)
)
(if fhzb
(setq fhzb (append fhzb zb2))
(setq fhzb zb2)
)
)
(princ "\n排序结果:")(princ fhzb)
(princ)
)
测试:
命令: test
排序结果:(A-S01--1.DWG A-S01--2.DWG A-S01--11.DWG A-S01--12.DWG A-S02--1.dwg
B-S01--1.DWG B-S02--1.dwg)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询