Создание исследовательского прототипа системы идентификации табличных данныхРефераты >> Программирование и компьютеры >> Создание исследовательского прототипа системы идентификации табличных данных
}
return(Returned);
}
//---------------------------------------------------------------------------
#ifndef NodeH
#define NodeH
//---------------------------------------------------------------------------
#endif
class Node
{public:
Node *Rgt;
Node *Lft;
char Letter;
long int Statistics;
Node();
~Node();
Node *JumpRight(char FindLet);
Node *RightPaste(char NewLet);
Node *LeftPaste(char NewLet);
Node *JumpLeft(char FindLet);
Node *AddWord(AnsiString Word);
Node *AddWordToEmptyTree(AnsiString Word);
void GetWords(TStrings *List,AnsiString Word=AnsiString());
};
#include <vcl.h>
#pragma hdrstop
#include "Node.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//-------------------------------
//Êîíñòðóêòîð
Node::Node()
{
Rgt=NULL;
Lft=NULL;
Letter='@';
Statistics=0;
}
//------------------------------------
Node::~Node()
{if (Rgt!=NULL) Rgt->~Node();
if (Lft!=NULL) Lft->~Node();
}
//-------------------------------------
//Ñîçäàòü óçåë ñïðàâà è âåðíóòü íà íåãî ññûëêó
Node *Node::RightPaste(char NewLet)
{Node *N=new Node;
N->Letter=NewLet;
N->Rgt=this->Rgt;
this->Rgt=N;
return(N);
}
//-------------------------------------
//Ñîçäàòü óçåë ñëåâà è âåðíóòü íà íåãî ññûëêó
Node *Node::LeftPaste(char NewLet)
{Node *N=new Node;
N->Letter=NewLet;
N->Rgt=this->Lft;
this->Lft=N;
return(N);
}
//-------------------------------------
//Äâèãàÿñü âïðàâî íàéòè áóêâó è âåðíóòü íà íå¸ ññûëêó
Node *Node::JumpRight(char FindLet)
{Node *N;
N=this;
while(N->Rgt!=NULL)
{if(N->Rgt->Letter<FindLet) N=N->Rgt;
else if(N->Rgt->Letter>FindLet)return(N->RightPaste(FindLet));//ñîçäàòü áóêâó è
//âåðíóòü íà íå¸ ññûëêó
else return(N->Rgt);};
//ñîçäàòü áóêâó è âåðíóòü íà íå¸ ññûëêó
return(N->RightPaste(FindLet));
}
//-------------------------------------
//Äâèãàÿñü âëåâî íàéòè áóêâó è âåðíóòü íà íå¸ ññûëêó
Node *Node::JumpLeft(char FindLet)
{
if (this->Lft==NULL) return(this->LeftPaste(FindLet));
if (this->Lft->Letter>FindLet) return(this->LeftPaste(FindLet));
else return(this->Lft);
}
//----------------
//Çàïîëíÿåì ïóñòîå ïîääåðåâî
Node *Node::AddWordToEmptyTree(AnsiString Word)
{char CurrentLet;
Node *N;
N=this;
while(!Word.IsEmpty()){CurrentLet=*Word.SubString(1,1).c_str();
Word=Word.SubString(2,Word.Length());
N=N->JumpLeft(CurrentLet); };
N->Statistics++;
return(N);
}
//----------------
//Äîáàâèòü ñëîâî â äåðåâî
Node *Node::AddWord(AnsiString Word)
{char CurrentLet;
Node *Drive;
if (this->Lft==NULL){ return(AddWordToEmptyTree(Word));};
Drive=this;
while(!Word.IsEmpty()){
do {CurrentLet=*Word.SubString(1,1).c_str();
Word=Word.SubString(2,Word.Length());
Drive=Drive->JumpLeft(CurrentLet);}
while(Drive->Letter==CurrentLet&&!Word.IsEmpty());
if (Drive->Letter!=CurrentLet) Drive=Drive->JumpRight(CurrentLet);
}
Drive->Statistics++;
return(Drive);
}
//---------------------------------------
void Node::GetWords(TStrings *List,AnsiString Word)
{Node *N;
N=this;
if (N->Statistics>0) List->Add(Word+AnsiString(N->Letter));
if (N->Lft!=NULL) N->Lft->GetWords(List,Word+AnsiString(N->Letter));
if (N->Rgt!=NULL) N->Rgt->GetWords(List,Word);
}
//---------------------------------------------------------------------------
#ifndef CompareH
#define CompareH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include <Dialogs.hpp>
#include "PositionTree.h"
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
const int MUPNum=3;
const int MaxID=5;
class TfCompare : public TForm
{
published: // IDE-managed Components
TPanel *Panel1;
TPanel *Panel2;
TPanel *Panel3;
TPanel *Panel4;
TStringGrid *sg;
TButton *Button2;
TOpenDialog *od;
TButton *Button3;
TButton *Button4;
TProgressBar *ProgressBar1;
TEdit *Edit1;
TButton *Button1;
void fastcall FormResize(TObject *Sender);
void fastcall Button1Click(TObject *Sender);
void fastcall Button2Click(TObject *Sender);
void fastcall Button3Click(TObject *Sender);
void fastcall FormCreate(TObject *Sender);
void fastcall FormDestroy(TObject *Sender);
void fastcall Button4Click(TObject *Sender);
void fastcall sgDblClick(TObject *Sender);
private: // User declarations
public: // User declarations
TPositionTree *Base,*Doc;
int CheckSum(AnsiString E1,AnsiString E2,int MaxPayLet);