From: Simon Pageot
Subject: N-ary tree...
Date: 
Message-ID: <924417618.793.14@news.remarQ.com>
We were given an assignement a little while ago, it is to create a program
in Lisp that would create a list that contains all possible n-ary tree for a
given level(height),  Since we only had 6 hours on lisp (the rest is on Ada
and ML).  The teacher decided to drop the assignement to only binary and
give the n-ary tree as a bonus.  I have the following for a binary tree and
it is working actually quite well.  But I can`t get the n-ary tree.  I
thought I could do it with going through a list and replace certain element
to create  the n-ary tree but it did not work. Here is what i have for a
binary tree and for a n-ary tree of an height of zero.(Hopefully, nobody
from my class will check the newsgroup...)

Help on the n-ary would be great I'd really would like to get the bonus
otherwise any comment good or bad on my binary tree would also help me
improve my skill with lisp and be welcome...

=-=-=-=--=-=-=

(setq L0 '((0 0)))

;;Binary tree right branch

(defun btreedroit (l h)
 (cond
 ((= h 1) (produit_elem 0  '((0 0))))
 (t(produit_elem 0 l))))
btreedroit
(btreedroit '() 1)
((0 (0 0)))

;;binary tree left branch

(defun btreegauche (l h)
  (cond
   ((= h 1)  (AF 0 '((0 0)) ))
   (t(AF 0 l))))
btreegauche
(btreegauche '() 1)
(((0 0) 0))

(defun btree (h)
  (cond
   ((= h 0) L0)
   ((= h 1) (append (append (btreegauche '() 1) (btreedroit '() 1)) (append
L0 L0))
   (t (append
       (append
       (append
       (append (btreegauche (btree (- h 1)) h) (btreedroit (btree(- h 1))
h))
       (produit (btree (- h 1)) (btree (- h 1))))
       (produit (btree (- h 2)) (btreegauche (btree (- h 1)) h)))
       (produit (btreedroit (btree (- h 1))h) (btree (- h 2)))))))

;;Add an element at the end of a list

(defun AF (ele l) (cond
                  ((null l) nil)
                  (t (cons (cons (car l) (cons ele nil)) (AF ele (cdr
l))))))


;;Check if element is part of a list
(defun membre (x l) (cond
                    ((null l) nil)
                    ((eq x (car l))t)
                    (t (membre x (cdr l)))))

;;Put two list together
(defun produit_elem (ele l) (cond
                            ((null l) nil)
                            (t (cons (cons ele (cons (car l)
nil))(produit_elem ele (cdr l))))))


(defun fin (ele l)(cond
     ((null l)nil)
     (t (cons (AjouterFin(ele L))(fin ele (cdr l))))))


(defun produit (l1 l2) (cond
                       ((null l1) nil)
                       (t (append (produit_elem (car l1) l2)(produit (cdr
l1) l2)))))

;;Main function
(defun  arbre (n h)
  (cond
      ((= n 0) (cons nil nil))
      ((= n 1) (let ((tree  nil))
   (while (> h 0)
    (setq tree (cons '(0) tree))
    (setq h (1- h))
    )tree))
     (( = n 2) (btree h))
))

;;  here is what I have so far for a n-ary tree that is actually working
(defun naire (n h)
 (cond
 ((= h 0) (car (root n 0)))
 ((= h 1) ?????)))

(defun root (n h)
  (let ((l nil) (x h) (y n))
    (while (> y 0)
      (setq l (cons x l))
      (setq y (1- y)))(cons l'())))
r