Lexikographisches Vergleichen zweier Listen
-
(defun list-compare (a b) (if (and (null a) (null b)) t (and (>= (first a) (first b)) (list-compare (rest a) (rest b)))))
Ist das richtig implementiert?
-
Nein. Damit Liste1 >= Liste2, müssen nicht alle Elemente jeweils >= sein, sondern nur das erste unterschiedliche.
-
Also so?
(defun list-compare (a b) (if (and (null a) (null b)) t (and (>= (first a) (first b)) (list-compare (rest a) (rest b)))))
-
äh, so?
(defun list-compare (a b) (if (and (null a) (null b)) t (if (>= (first a) (first b)) t (list-compare (rest a) (rest b)))))
-
Sorry. SO?
(defun list-compare (a b) (if (and (null a) (null b)) t (if (= (first a) (first b)) (list-compare (rest a) (rest b)) (>= (first a) (first b)))))
-
Du mußt auch noch die beiden Fälle berücksichtigen, daß genau eine Liste leer ist.
-
Ich nehme (= (length a) (length b)) an