Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-struct arbol (valor izq der ))
- (define arbol3 (make-arbol 5
- (make-arbol 10
- (make-arbol 2
- (make-arbol 4
- empty
- empty)
- (make-arbol 8
- empty
- empty))
- (make-arbol 6
- (make-arbol 3
- empty
- empty)
- empty))
- (make-arbol 30
- (make-arbol 15
- empty
- empty)
- (make-arbol 25
- (make-arbol 1
- empty
- empty)
- (make-arbol 9
- empty
- empty)))
- )
- )
- (define lista1 (list 1 2 3 4 5 6))
- (define lista2 (list 3 6 9 12))
- (define lista3 (list 5 10 2 4 8 6 3 30 15 25 1 9))
- ;Autores: Juan Felipe Arango Guzman, 202060066. Diego Fernando Llanos Mondragon, .
- ;Juan Sebastian Grajales Samudio; .
- ;Fecha: 14/09/2020
- ;Contrato: contener: listanumerica, arbol -> booleano
- ;Proposito: Determinar si los elementos de una lita estan contenidos dentro de un arbol
- ;Ejemplos:
- ;(comparar lista1 (preorden arbol3)) #true
- ;(comparar lista2 (preorden arbol3)) #false
- ;(comparar lista3 (preorden arbol3)) #true
- ;Definiciones:
- (define (contener lst arb)
- (cond
- [(empty? lst)#T]
- [(conteneraux arb (first lst))
- (contener (rest lst) arb)]
- [(not(conteneraux arb (first lst)))
- #F]
- )
- )
- ;Contrato: compararaux: lst, num -> booleano
- (define (conteneraux lst num)
- (cond
- [(empty? lst) #F]
- [(equal? (first lst) num) #T]
- [else (conteneraux (rest lst) num)]
- )
- )
- ;Contrato: preorden: arbol-> lista
- (define (preorden arbol)
- (cond
- [(empty? arbol) empty]
- [else (append
- (cons (arbol-valor arbol) empty)
- (preorden (arbol-izq arbol))
- (preorden (arbol-der arbol))
- )]))
- ;Pruebas:
- (check-expect (contener lista1 (preorden arbol3)) #true)
- (check-expect (contener lista2 (preorden arbol3)) #false)
- (check-expect (contener lista3 (preorden arbol3)) #true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement