Skip to content

Instantly share code, notes, and snippets.

@crowl
Created December 15, 2015 17:37
Show Gist options
  • Save crowl/a052220c6b525f876b39 to your computer and use it in GitHub Desktop.
Save crowl/a052220c6b525f876b39 to your computer and use it in GitHub Desktop.
;;; 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