Search the Community
Showing results for tags 'nth-replace'.
-
I've completed MergeSort algorithm implementation in Autolisp based on Ellis Dee's vb6 version here: http://www.vbforums.com/showpost.php?p=2909257&postcount=12 The problem is that I need to replace nth atom in the lisp array, and the only way I can currently accomplish this, is by iterating the entire list. This takes, what would be a spectacular sorting algorithm, and destroys it's efficiency by iterating the list nth(log) times. I'm going to try not to muddy the water too much, but here is my nth-replace function based on Michels nth-remove function... (defun nth-replace (n_atom f_list f_n / ) ;replaced the nth element of a list ;n_atom is new atom ;f_list is list to be operated on ;f_n is the index that will be replaced (if (and (numberp f_n) (listp f_list)) (if (and (>= f_n 0) (< f_n (length f_list)) n_atom) (progn (repeat f_n (setq f_list (append (cdr f_list) (list (car f_list)))) ) (setq f_list (append (cdr f_list) (list n_atom))) (repeat (- (length f_list) f_n 1) (setq f_list (append (cdr f_list) (list (car f_list)))) ) ) ) ) f_list );defun I'm not completely new to autolisp, but I'm hoping there's a fundamental function I'm overlooking that can either replace an atom at a certain level, or can return a list up to a certain atom (nth instance), and then I can append my change, and then the latter half of the list.
- 18 replies
-
- atom
- atom replace
-
(and 3 more)
Tagged with: