calculate the entropy using the binary tree

Hi, I programmed a program to calculate the entropy. So far I have done reading test.txt from the command line. But now I do not know how to save words from test.txt to the binary tree and compare them. I thought this but I do not know how to take the floor and put it into a tree. Someone help me? thank you


1
2
3
4
5
6
if (str1 < str2)
  // left
else if (str1 > str2)
  // right
else
  // are the same 


This I have done thus far
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
41
42
43
44
45
46
47
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
   ofstream file1; // input
   file1.open("test.txt", ios::out);
   file1 << "mouse" << endl << "computer" << endl << "mouse";
   file1.close();

   string word1, word2;
   string word3;


char name[256];
cout << "Enter the file name:";
cin>>name;

ifstream file(name);
if(!file.is_open())
   {
      cout << "Can not open file! Check the path to the file!" << endl;
      system("pause");
      exit(-5);
   }
if(file.is_open())
   {
      cout << "File open.\n\n" << endl;
	     ifstream soubor2; // read
         file2.open("test.txt", ios::in);
         file2 >> jmeno >> word1 >> word2;
         cout << word1 << " " << word2 << " " << word3 << endl;
         file2.close();
   }
}

     
}

Last edited on
Topic archived. No new replies allowed.