Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Recorrido preorden
- (define-struct arbol (valor hizq hder))
- (define arbolEjemplo (make-arbol 5
- (make-arbol 9
- (make-arbol 12 empty empty)
- (make-arbol 10 empty empty))
- (make-arbol 8
- (make-arbol 18 empty empty)
- (make-arbol 14 empty empty))))
- ;;Autor: Carlos A Delgado
- ;;Fecha: 22 de Agosto de 2020
- ;;Contrato: arbol -> lista de numeros
- (define (recorrido-preorden arb)
- (cond
- [(null? arb) '()]
- [else
- (append
- (cons (arbol-valor arb) empty)
- (recorrido-preorden (arbol-hizq arb))
- (recorrido-preorden (arbol-hder arb)))
- ]
- ))
- (recorrido-preorden arbolEjemplo)
- ;;Autor: Carlos A Delgado
- ;;Fecha: 22 de Agosto de 2020
- ;;Contrato: arbol -> lista de numeros
- (define (recorrido-inorden arb)
- (cond
- [(null? arb) '()]
- [else
- (append
- (recorrido-inorden (arbol-hizq arb))
- (cons (arbol-valor arb) empty)
- (recorrido-inorden (arbol-hder arb)))
- ]
- ))
- (recorrido-inorden arbolEjemplo)
- ;;Autor: Carlos A Delgado
- ;;Fecha: 22 de Agosto de 2020
- ;;Contrato: arbol -> lista de numeros
- (define (recorrido-posorden arb)
- (cond
- [(null? arb) '()]
- [else
- (append
- (recorrido-posorden (arbol-hizq arb))
- (recorrido-posorden (arbol-hder arb))
- (cons (arbol-valor arb) empty)
- )
- ]
- ))
- (recorrido-posorden arbolEjemplo)
- ;;Arbol de ejemplo en clase
- ;.
- (define arbolEjemploClase
- (make-arbol 10
- (make-arbol 7
- (make-arbol 15
- (make-arbol 7
- (make-arbol 1 empty empty)
- (make-arbol 2 empty empty))
- (make-arbol 6 empty empty))
- (make-arbol 9
- (make-arbol 14 empty empty)
- (make-arbol 16
- (make-arbol 4 empty empty)
- (make-arbol 8 empty empty))))
- (make-arbol 9
- (make-arbol 8 empty empty)
- (make-arbol 6
- (make-arbol 3 empty empty)
- (make-arbol 5 empty empty)))))
- (recorrido-preorden arbolEjemploClase)
- (recorrido-inorden arbolEjemploClase)
- (recorrido-posorden arbolEjemploClase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement