SHOW:
|
|
- or go back to the newest paste.
1 | ;;Recorrido preorden | |
2 | ||
3 | (define-struct arbol (valor hizq hder)) | |
4 | ||
5 | (define arbolEjemplo (make-arbol 5 | |
6 | (make-arbol 9 | |
7 | (make-arbol 12 empty empty) | |
8 | (make-arbol 10 empty empty)) | |
9 | (make-arbol 8 | |
10 | (make-arbol 18 empty empty) | |
11 | (make-arbol 14 empty empty)))) | |
12 | ||
13 | ;;Autor: Carlos A Delgado | |
14 | ;;Fecha: 22 de Agosto de 2020 | |
15 | ;;Contrato: arbol -> lista de numeros | |
16 | (define (recorrido-preorden arb) | |
17 | (cond | |
18 | [(null? arb) '()] | |
19 | [else | |
20 | (append | |
21 | (cons (arbol-valor arb) empty) | |
22 | (recorrido-preorden (arbol-hizq arb)) | |
23 | (recorrido-preorden (arbol-hder arb))) | |
24 | ] | |
25 | )) | |
26 | ||
27 | (recorrido-preorden arbolEjemplo) | |
28 | ;;Autor: Carlos A Delgado | |
29 | ;;Fecha: 22 de Agosto de 2020 | |
30 | ;;Contrato: arbol -> lista de numeros | |
31 | (define (recorrido-inorden arb) | |
32 | (cond | |
33 | [(null? arb) '()] | |
34 | [else | |
35 | (append | |
36 | (recorrido-inorden (arbol-hizq arb)) | |
37 | (cons (arbol-valor arb) empty) | |
38 | (recorrido-inorden (arbol-hder arb))) | |
39 | ] | |
40 | )) | |
41 | (recorrido-inorden arbolEjemplo) | |
42 | ||
43 | ||
44 | ;;Autor: Carlos A Delgado | |
45 | ;;Fecha: 22 de Agosto de 2020 | |
46 | ;;Contrato: arbol -> lista de numeros | |
47 | (define (recorrido-posorden arb) | |
48 | (cond | |
49 | [(null? arb) '()] | |
50 | [else | |
51 | (append | |
52 | (recorrido-posorden (arbol-hizq arb)) | |
53 | (recorrido-posorden (arbol-hder arb)) | |
54 | (cons (arbol-valor arb) empty) | |
55 | ) | |
56 | ] | |
57 | )) | |
58 | (recorrido-posorden arbolEjemplo) | |
59 | ||
60 | ||
61 | ;;Arbol de ejemplo en clase | |
62 | ;. | |
63 | ||
64 | ||
65 | (define arbolEjemploClase | |
66 | (make-arbol 10 | |
67 | (make-arbol 7 | |
68 | (make-arbol 15 | |
69 | (make-arbol 7 | |
70 | (make-arbol 1 empty empty) | |
71 | (make-arbol 2 empty empty)) | |
72 | (make-arbol 6 empty empty)) | |
73 | (make-arbol 9 | |
74 | (make-arbol 14 empty empty) | |
75 | (make-arbol 16 | |
76 | (make-arbol 4 empty empty) | |
77 | (make-arbol 8 empty empty)))) | |
78 | (make-arbol 9 | |
79 | (make-arbol 8 empty empty) | |
80 | (make-arbol 6 | |
81 | (make-arbol 3 empty empty) | |
82 | (make-arbol 5 empty empty))))) | |
83 | ||
84 | ||
85 | (recorrido-preorden arbolEjemploClase) | |
86 | (recorrido-inorden arbolEjemploClase) | |
87 | (recorrido-posorden arbolEjemploClase) |