PHP код:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
class Policlinnica
{
private:
struct Node
{
char family [30];
char name [30];
char fathername [30];
char adress[30];
int polic;
long int medkart;//медкарта
Node* left;
Node* right;
Node()
{
strcpy(this->family, "");
strcpy(this->name, "");
strcpy(this->fathername, "");
strcpy(this->adress, "");
this->polic=0;
medkart= 0;
this->left=0;
this->right=0;
}
Node(Node const& rhs)
{
strcpy(family, rhs.family);
strcpy(name, rhs.name);
strcpy(fathername, rhs.fathername);
strcpy(adress, rhs.adress);
polic=rhs.polic;
medkart=rhs.medkart;
left=rhs.left;
right=rhs.right;
}
void insert(Node const& rhs)
{
if(rhs.medkart < medkart)
{
if(!left)
left = new Node(rhs);
else
left->insert(rhs);
}
if(rhs.medkart > medkart)
{
if(!right)
right = new Node(rhs);
else
right->insert(rhs);
}
}
void print() const
{
if(left)
left->print();
cout <<"family "<< family << "\n\n";
cout <<"name "<< name << "\n\n";
cout <<"fathername "<< fathername << "\n\n";
cout <<"adress "<< adress << "\n\n";
cout <<"polic "<< polic << "\n\n";
cout <<"medkart "<< medkart << "\n\n";
cout << "===============================================";
cout << "\n";
if(right)
right->print();
}
};
Node* pRoot;//êîðíåâîé
public: Policlinnica() : pRoot(0){}
void insert(Node const& rhs)
{
if(!pRoot)
pRoot = new Node(rhs);
else
pRoot->insert(rhs);
}
void LoadFile();
void print() const
{
if(pRoot)
pRoot->print();
}
};
void Policlinnica::LoadFile()
{
Node tmp;
FILE* f=fopen("in.txt","rt");
if (f)
{
while (!feof(f))
{
fscanf(f, "%s %s %s %s %d %d %d", tmp.family, tmp.name, tmp.fathername, tmp.adress, &tmp.polic, &tmp.medkart);
insert(tmp);
}
fclose(f);
}
else
cout << "File not found";
}
int main()
{
Policlinnica obj;
obj.LoadFile();
obj.print();
}
Напишите пожалуйста функцию удаления по "медкарте". Никак не получается.