|

JavaMatlabPhpHtmlJavaScriptCSSC#Delphi 1


Linux Unix AutoCAD 3D Access Orcad

: , .

 

#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
class treeNode{
public:
int key; //
int info; //
treeNode *LLink, *RLink; //
treeNode(){key=0;LLink=RLink=NULL;} //
treeNode(int k, int info_c){key=k;info=info_c;LLink=RLink=NULL;} //
~treeNode(){ //
if(RLink!=NULL)delete RLink; //
if(LLink!=NULL)delete LLink;
}
// .
void insert(int number, int info, treeNode *ptr);
treeNode* find(treeNode *ppp,int kkk); //
};
treeNode*
treeNode::find(treeNode *ppp,int kkk) //
{
while((ppp!=NULL)&&(ppp->key!=kkk)){
if(ppp->key<kkk){
cout<<" "<<ppp->key<<" ."<<endl;
ppp=ppp->RLink;
}
else {
cout<<" "<<ppp->key<<" ."<<endl;
ppp=ppp->LLink;
}
}
return ppp;
}
void treeNode::insert(int n, int inf, treeNode *ptr){
cout<<"----------------"<<endl;
cout<<" ("<<n<<";"<<inf<<")\n";
int flag=1;
treeNode *p, *q;
p=ptr;
while(flag){
if(n < p->key){
q=p->LLink; //a3
cout<<" "<<p->key<<endl<<" ";
if(q==NULL)cout<<"NULL"<<endl;else cout<<q->key<<endl;
if(q==NULL){
flag=0;
cout<<" ("<<n<<","<<inf<<")"<<endl;
q=new treeNode(n,inf);
cout<<" : "<<p->key<<"->LLink = "<<q->key<<endl;
p->LLink=q;
}else p=q;
}else if(n > p->key){
q=p->RLink; //a4
cout<<" "<<p->key<<endl<<" ";
if(q==NULL)cout<<"NULL"<<endl;else cout<<q->key<<endl;
if(q==NULL){
flag=0;
cout<<" ("<<n<<","<<inf<<")"<<endl;
q=new treeNode(n,inf);
cout<<" : "<<p->key<<"->RLink = "<<q->key<<endl;
p->RLink=q;
}else p=q;
}else if(n == p->key){
cout<<" "<<endl;
flag=0;// WHILE
}
}
getch();
}
void main() //
{
clrscr();
randomize();
int k_elem;
char rand_elem;
treeNode *root=new treeNode; //
cout<<endl<<" ?";
cin>>k_elem;
cout<<endl<<" ? (y/n) ";
cin>>rand_elem;
int num,inf;
for(int tr_i=0;tr_i<k_elem;tr_i++){
if(rand_elem=='n'){
//
cout<<endl<<": ";
cin>>num;
cout<<": ";
cin>>inf;
}else{
//
num=random(100)+1;
inf=random(100)+1;
}
root->insert(num,inf,root);
}
//--- ---//
if(root!=NULL) delete root; //clear memory - binary trees
}

: 8316

:C





php mysql



C


 


? :

, ? Google !

 
 

© life-prog.ru .