各位前辈: 请帮忙,我想对用户输入的五个数进行排序,用冒泡排序法来做, 但在第二层循环里如果下一元素大过当前元素时,想给它对调一下,不 知道用LISP如何对调,请高手帮帮忙,先谢谢了! (defun c:bubble(/ a a1 a2 a3 a4 a5 temp n i j) (princ "\n请输入五个整数,系统帮您排序!") (setq a1 (getint "\n请输入第一个数:")) (setq a2 (getint "\n请输入第二个数:")) (setq a3 (getint "\n请输入第三个数:")) (setq a4 (getint "\n请输入第四个数:")) (setq a5 (getint "\n请输入第五个数:")) (setq a (list a1 a2 a3 a4 a5)) (setq n (length a)) (setq i 0) (setq j 0) (repeat (1- n) (repeat (- n i 1) (if (> (nth j a) (nth (1+ j) a)) ;;此处对调前后两个元素值有什么函数可以做得到? (setq temp (nth (1+ j) a)) (setq (nth (1+ j) a) (nth j a)) (setq (nth j a ) temp) ;;******************************************** ) (setq j (1+ j)) ) (setq i (1+ i)) ) (setq i 0) (repeat (1- n) (princ "\n") (princ (nth i a)) ) (princ) ) |