Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;https://swebse29.univalle.edu.co/sra/
- ;;tree
- ;;empty
- ;;(symbol tree tree tree)
- (define-struct tree
- (valor izquierda centro derecha))
- ;tree-x
- ;empty
- ;(X tree-x tree-x tree-x)
- (define-struct tree-x
- (valor izquierda centro derecho)
- )
- (define (contar tree-x)
- (cond
- [(empty? tree-x) 0]
- [else
- (+
- 1
- (contar (tree-x-izquierda tree-x))
- (contar (tree-x-centro tree-x))
- (contar (tree-x-derecho tree-x))
- )
- ]
- )
- )
- (define (contar-simbolos tree-x)
- (cond
- [(empty? tree-x) 0]
- [else
- (+
- (cond
- [(symbol? (tree-x-valor tree-x)) 1]
- [else 0]
- )
- (contar-simbolos (tree-x-izquierda tree-x))
- (contar-simbolos (tree-x-centro tree-x))
- (contar-simbolos (tree-x-derecho tree-x))
- )
- ]
- )
- )
- (define (aplanar tree-x)
- (cond
- [(empty? tree-x) empty]
- [else
- (cons
- (tree-x-valor tree-x)
- (append
- (aplanar (tree-x-izquierda tree-x))
- (aplanar (tree-x-centro tree-x))
- (aplanar (tree-x-derecho tree-x))
- )
- )
- ]
- )
- )
- (define (contiene-simbolo? tree-x sym)
- (cond
- [(empty? tree-x) #f]
- [else
- (or
- (cond
- [(symbol? (tree-x-valor tree-x))
- (eq? (tree-x-valor tree-x) sym)]
- [else #f]
- )
- (contiene-simbolo? (tree-x-izquierda tree-x) sym)
- (contiene-simbolo? (tree-x-centro tree-x) sym)
- (contiene-simbolo? (tree-x-derecho tree-x) sym)
- )
- ]
- )
- )
- (define (mapeo procedimiento tree-X)
- (cond
- [(empty? tree-X) empty]
- [else
- (make-tree-x
- (procedimiento (tree-x-valor tree-X))
- (mapeo procedimiento (tree-x-izquierda tree-X))
- (mapeo procedimiento (tree-x-centro tree-X))
- (mapeo procedimiento (tree-x-derecho tree-X))
- )
- ]
- )
- )
- (define arbol1 empty)
- (define arbol2
- (make-tree-x
- 'a
- (make-tree-x 'b empty empty (make-tree-x 2 empty empty empty))
- empty
- (make-tree-x #t empty empty empty))
- )
- (define arbolSimbolo
- (make-tree-x
- 'a
- (make-tree-x 'b empty empty (make-tree-x 'a empty empty empty))
- empty
- (make-tree-x 't empty empty empty))
- )
- ;;Contar en arbol n-ario
- (define (contar-nario tree)
- (cond
- [(empty? tree) 0]
- [else
- (+
- 1
- (contar-aux (arbol-nario-lista-hijos tree))
- )
- ]
- )
- )
- (define (contar-aux lista)
- (cond
- [(empty? lista) 0]
- [else
- (+ (contar-nario (car lista)) (contar-aux (cdr lista)))
- ]
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement