-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno.cpp
More file actions
40 lines (32 loc) · 819 Bytes
/
no.cpp
File metadata and controls
40 lines (32 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "no.h"
No::No()
{
}
No::No(No * esquerda, No * direita){
this->esquerda = esquerda;
this->direita = direita;
this->frequencia = esquerda->getFrequencia() + direita->getFrequencia();
this->caractere = '+';
this->pai = NULL;
esquerda->pai = this;
direita->pai = this;
}
No::No(char caractere, int frequencia){
this->caractere = caractere;
this->frequencia = frequencia;
this->direita = NULL;
this->esquerda = NULL;
}
bool No::isFolha(){
if(direita == NULL && esquerda == NULL)
return true;
return false;
}
int No::getFrequencia(){
if(isFolha())
return this->frequencia;
return esquerda->getFrequencia() + direita->getFrequencia();
}
char No::getCaractere(){
return this->caractere;
}