#include
#include
#include
#include
#include
using namespace std;
struct node{
char c;
int weight;
string code = "";
node *left_child;
node *right_child;
};
string read_file(string input_file){
string input = "";
ifstream fin;
fin.open(input_file.c_str());
if ( fin.fail() ){
cout c){
n3->left_child = & (*node_list.begin());
node_list.pop_front();
n3->right_child = & (*node_list.begin());
node_list.pop_front();
}
else{
n3->right_child = & (*node_list.begin());
node_list.pop_front();
n3->left_child = & (*node_list.begin());
node_list.pop_front();
}
n3->c = n3->left_child->c;
cout right_child->weight;
node_list.push_back((*n3)); // put combined tree back to list
node_list.sort(); // sort the list again for another combination
}
}
*/
void output_code(string code, node *n, list & node_list, int height){
if ((n->left_child == nullptr) && (n->right_child == nullptr)){
n->code = code;
node_list.push_back((*n));
return;
}
output_code(code + '0', n->left_child, node_list, height + 1);
output_code(code + '1', n->right_child, node_list, height + 1);
}
void generate_code_file(list n){
ofstream fout;
fout.open("code.txt");
list::iterator itr;
for (itr = n.begin(); itr != n.end(); itr++) {
fout code c = n3->left_child->c;
cout left_child->weight + n3->right_child->weight;
node_list.push_back((*n3)); // put combined tree back to list
node_list.sort(); // sort the list again for another combination
list::iterator itr;
for (itr = node_list.begin(); itr != node_list.end(); itr++) { // print all the address of all element in the list
cout right_child = left_child;
n3->left_child = right_child;
}
n3->c = n3->left_child->c;
cout left_child->weight + n3->right_child->weight;
node_list.push_back((*n3)); // put combined tree back to list
node_list.sort(); // sort the list again for another combination
list::iterator itr;
for (itr = node_list.begin(); itr != node_list.end(); itr++) { // print all the address of all element in the list
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78391173/why-the-functions-applied-to-a-list-changes-the-address-of-elements-in-it[/url]
void generate_code_file(list n){ ofstream fout; fout.open("code.txt"); list::iterator itr; for (itr = n.begin(); itr != n.end(); itr++) { fout code c = n3->left_child->c; cout left_child->weight + n3->right_child->weight; node_list.push_back((*n3)); // put combined tree back to list node_list.sort(); // sort the list again for another combination list::iterator itr; for (itr = node_list.begin(); itr != node_list.end(); itr++) { // print all the address of all element in the list cout right_child = left_child; n3->left_child = right_child; } n3->c = n3->left_child->c; cout left_child->weight + n3->right_child->weight; node_list.push_back((*n3)); // put combined tree back to list node_list.sort(); // sort the list again for another combination list::iterator itr; for (itr = node_list.begin(); itr != node_list.end(); itr++) { // print all the address of all element in the list cout