next up previous
Next: 6.3 頂点リスト Up: 6 グラフ Previous: 6.1 グラフの記述

6.2 基本関数

ノードが今はシンボルであらわされているが, ノードを扱うための基本関数を定義し,それを 使ってゆく形で進める.
(defun node-equal (a b) (equal a b))

(defun node-member (n path)
  (cond
      ((null path) nil)
    ((node-equal n (car path)) path)
    (t (node-member n (cdr path)))))

(defun node-remove (a l)
  (cond
      ((null l) nil)
    ((node-equal a (car l))
     (node-remove a (cdr l)))
    (t (cons (car l) (node-remove a (cdr l))))))

(defun node-union (a b)
  (cond
      ((null a) b)
    ((node-member (car a) b)
     (node-union (cdr a) b))
    (t (cons (car a) (node-union (cdr a) b)))))
ノードがシンボルではなく,リストや集合で表される場合に この基本関数のnode-equalを変更するだけですむようにする.

generated through LaTeX2HTML. M.Inaba 平成18年5月7日