Created
December 15, 2015 17:37
-
-
Save crowl/a052220c6b525f876b39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; P9 - Inserción de Strings en Listas | |
(define compare-lex | |
(lambda (a b) | |
(string-ci<? (substring a 0 1) (substring b 0 1)))) | |
(define insert | |
(lambda (strlst lst) | |
(letrec ((combine (lambda (a b) | |
(cond | |
((null? a) b) | |
((null? b) a) | |
((compare-lex (car a) (car b)) | |
(cons (car a) (combine (cdr a) b))) | |
(else (cons (car b) (combine a (cdr b))))))) | |
(ordered (sort lst compare-lex))) | |
(combine strlst ordered)))) | |
;;; Prueba | |
(print (insert '("Esteban" "Maria") '("Alex" "Maria" "Cristopher" "Roberto" "Esteban"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment