"Pat Monardo" <[EMAIL PROTECTED]> writes:

> I dont understand. For example this is typical from red-black tree
> (if (eq (p z) (left (p (p z))))
> 
>     (let ((y (right (p (p z)))))
> 
>         (cond ((eq (color y) :RED)
> 
>             (setf (color (p z)) :BLACK)
> 
>             (setf (color y) :BLACK)
> 
>             (setf (color (p (p z))) :RED)
> 
>             (setf z (p (p z))))
> 
> etc..
> 
> (sorry the formatting is strange on move to windows from linux emacs; dont
> really know emacs but I am using ILISP)
> 
> where p is CLRS speak for parent. how would you improve something
> like this?

What about something like

(let ((parent (parent node))
      (grandparent (parent parent)))
  (if (eq parent (left grandparent))
    (let ((neighbor (right grandparent)))
      (cond ((eq (color neighbor) :RED)
             (setf (color parent) :BLACK)
             (setf (color neighbor) :BLACK)
             (setf (color grandparent)) :RED)
             (setf node grandparent))
            )))

Nicolas.

Reply via email to