Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define CONT5 (list "Pagina" "sem" "conteudo" ":("))
- (define PAG5 (make-pag-web "Pagina 5" CONT5))
- (define CONT4 (list "Outro" "Site" PAG5))
- (define PAG4 (make-pag-web "Pagina 4" CONT4))
- (define CONT3 (list "Imagens" (circle 10 "solid" "black")(circle 10 "solid" "blue")))
- (define PAG3 (make-pag-web "Pagina 3" CONT3))
- (define CONT2 (list "Links" PAG3 PAG4))
- (define PAG2 (make-pag-web "Pagina 2" CONT2))
- (define CONT1 (list "Site" "Exemplo" PAG2))
- (define PAG1 (make-pag-web "Pagina 1" CONT1))
- ;; profundidade: pag-web → Número
- ;; Dada uma Página web devolve o número máximo de níveis que ela contém
- ;; Exemplos:
- ;; (profundidade PAG1) = 3
- ;; (profundidade PAG2) = 2
- (define(profundidade p)
- (cond
- [(= 0 (procuraPag (pag-web-conteudo p)))0]
- [else (procuraPag(pag-web-conteudo p)) ]
- )
- )
- ;;Testes:
- (check-expect(profundidade PAG1)3)
- (check-expect(profundidade PAG2)2)
- ;; procuraPag: Lista-conteudo → Número
- ;; Dada uma Lista de conteúdo devolve o número máximo de níveis de Páginas web que ela contém
- ;; Exemplos:
- ;; (procuraPag CONT1) = 3
- ;; (procuraPag CONT5) = 0
- (define(procuraPag c)
- (cond
- [(empty? c)0]
- [(pag-web? (first c))(+ 1 (profundidade (first c))(procuraPagJaAchou (rest c)))]
- [else (procuraPag (rest c))]
- )
- )
- (check-expect(procuraPag CONT1)3)
- (check-expect(procuraPag CONT5)0)
- ;; procuraPagJaAchou: Lista-conteudo → Número
- ;; Dada uma Lista de conteúdo devolve o número máximo de níveis de Páginas web que ela contém, deixando
- ;; de contar o primeiro nível de páginas
- ;; Exemplos:
- ;; (procuraPag CONT1) = 2
- ;; (procuraPag CONT2) = 1
- (define(procuraPagJaAchou c)
- (cond
- [(empty? c)0]
- [(pag-web? (first c))(+(profundidade (first c))(procuraPagJaAchou (rest c)))]
- [else (procuraPagJaAchou (rest c))]
- )
- )
- (check-expect(procuraPagJaAchou CONT1)2)
- (check-expect(procuraPagJaAchou CONT2)1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement