#include"thuvien.h"
int DocFile(char *tenfile)//Doc danh sach cac tu co trong tu dien
{
errno_t fl;
FILE *f; char line[100];
fl = fopen_s(&f, tenfile, "r");
if (f == NULL)return 0;
while (!feof(f))
{
if (fgets(line, 100, f) == NULL)
break;
cout << line << '\n';
}
fclose(f);
return 1;
}
void Init_tree(BST &root)//khoi tao cay BST
{
root = NULL;
}
NODEPTR Tao_node(char x[30])//Tao node cho cay BST
{
NODEPTR p;
p = new NODE;
strcpy_s(p->tu, x);
p->left = NULL;
p->right = NULL;
return p;
}
void InsertTree(BST &root, char x[30])//Them node vao cay BST
{
if (root == NULL)
root = Tao_node(x);
else
{
if /*(x == root->tu)*/ (strcmp(root->tu, x) == 0)
{
cout << "\nTu da co trong tu dien!!!,vui long nhap lai tu khac :";
return;
}else
if /*(x < root->tu)*/ (strcmp(root->tu, x) > 0)
InsertTree(root->left, x);
else
InsertTree(root->right, x);
}
}
void NhapTree(BST &root)//Nhap tu cho BST
{
char x[30];
while (1)
{
cout<<"\nNhap tu dien(Nhap q de dung): ";
cin.getline(x,30);
if (strcmp(x, "q") ==0)
break;
InsertTree(root, x);
}
}
void LNR(BST root)//Cay BST LNR
{
if (root != NULL)
{
LNR(root->left);
cout<<" "<< root->tu;
LNR(root->right);
}
}
NODEPTR search_node(BST root, char x[30])
{
NODEPTR p = root;
cout << "\nNhap tu can co trong van ban muon kiem tra:";
cin.getline(x, 30);
while (p != NULL)
{
if (strcmp(p->tu,x)==0) return p;
else if (strcmp(x , p->tu)<0) p = p->left;
else p = p->right;
}
return NULL;
}
-----------------------
#include"thuvien.h"
void main()
{
cout << "\n_________________Cac tu trong van ban_____________________________" << endl;
DocFile("TextFile1.txt");
cout << "\nKiem tra tu trong tu dien:" << endl;
cout << "\n_________________Phan nhap du lieu cho tu dien _____________________________"<<endl;
BST tree;
Init_tree(tree);
NhapTree(tree);
cout << endl;
cout << endl;
cout << "\__________________CAY BST theo thu tu LNR______________________________________" << endl;
LNR(tree);
cout << endl;
char x[30];
if (search_node(tree, x) != NULL)
{
cout << "=>Tu co trong tu dien";
}
else
cout << "=>Tu khong co trong tu dien";
cout << endl;
system("pause");
}
h làm sao để so sánh những từ trong văn bản và những từ trong thư viện… những từ nào k có trong thư viện thì xuất ra… thanks ạ