I'm making a Huffman tree and I want to show the result of the message on the screen. Something like:
Mensaje Original: Hola mundo
Huffman: 10010100010101010101
But I have problems saving the numbers to print them in order of the message.
/*
* Lo ideal sería que fuera vector<char*> Numero
* para que guardara las cosas algo así:
* Numero[] = { "1001", "001", "1111"....}
* enconces al mandar imprimir a Numero[0] saldría
* 1001 en pantalla.
*/
vector<char> Letras;
vector<int> Numero;
cout << "Peso binario de cada letra" << endl;
for(CodigoHuffmanMap::const_iterator it = Bin.begin(); it != Bin.end(); ++it){
// Imprimir y guardar la letra.
cout << it->first << " = ";
Letras.push_back(it->first);
// Imprimir el número. E.g. 1001
copy(it->second.begin(), it->second.end(), ostream_iterator<bool>(cout));
cout << endl;
// Guardar la cadena de números "1010" en vector<char*> Numero
copy(it->second.begin(), it->second.end(), back_inserter(Numero));
}
cout << "Comprension" << endl;
for(int i = 0; i < strlen(EnunciadoPrueba); i++){
for(int j = 0; j < Letras.size(); j++){
if(Letras[j] == EnunciadoPrueba[i]){
// Comprueba que está en orden imprimiendo Letras[j]
// en lugar de Numero[j]
cout << Numero[j];
continue;
}
}
}
cout << endl << "Todos los numeros que deberian salir en pantalla." << endl;
for(int i = 0; i < Numero.size(); i++)
cout << Numero[i];
The problem is that when I save the numbers I can only do it with vector < int & Number and that generates the outputs:
cout << Numero[0]; // 1
When I want to save it in a string or char, so that:
cout << Numero[0]; // 10001