ALL NICE !
(defun f (L n)
(if (> n (car l)) (cons n l)
(cons (car l) (f (cdr l) n))))
Test
(f '(6 5 4 3 2) 1) ; (6 5 4 3 2 1)
(f '(9 8 7 6 5 3) 1) ; (9 8 7 6 5 3 1)
(f '(9 8 7 6 5 3) 10) ; (10 9 8 7 6 5 3)
(f '(9 8 7 6 5 3) 3) ; (9 8 7 6 5 3 3)
(f '(9 8 7 6 5 3) 5) ; (9 8 7 6 5 5 3)
(f '(9 8 7 6 5 3) 4) ; (9 8 7 6 5 4 3)
(f '(9 8 7 6 5 3) 9) ; (9 9 8 7 6 5 3)
Not exactly what the OP asked for. He wanted the list to stay the same length by dropping the smallest value after inserting the new value.
I'm sorry to do wrong the mean .
(defun f (l n / f1)
(defun f1 (L n)
(if (< n (car l))
(cons n l)
(cons (car l) (f1 (cdr l) n))
)
)
(reverse (cdr (f1 (reverse l) n)))
)
My Test result
测试耗时......毫秒 / 相对速度 ...... 迭代次数32768...:
PH:F1......60 / 15.34......<Fastest>
LM:F1......160 / 5.75......
PH:F2......220 / 4.18......
F......230 / 4.00......
HB:F......260 / 3.54......
EA:F......260 / 3.54......
INSVAL......920 / 1.00......<Slowest>