Return to Snippet

Revision: 68478
at January 19, 2015 04:57 by 8ivana8


Initial Code
bool ExistsLeftChild(pok_element *T){
    if(T->left) 
		return true;
    else 
		return false;
}
     
bool ExistsRightChild(pok_element *T){
    if(T->right) 
		return true;
    else 
		return false;
}
     
void InsertBS(int x, pok_element *T){
    bool dalje = true;
    pok_element *cvor = T;
    
	do{
	    if(x > cvor->label){
		    if(ExistsRightChild(cvor)) 
				cvor = cvor->right;
		    else {
			    CreateRightB(x, cvor);
			    dalje = false;
		    }
	    }
	    else if(x < cvor->label){
		    if(ExistsLeftChild(cvor)) 
				cvor = cvor->left;
		    else {
			    CreateLeftB(x, cvor);
			    dalje = false;
		    }
	    }
	    else dalje = false;
	}while(dalje);
}
     
void searchBT(int x, pok_element *T){
    if(T->label == x){
	    cout << "Element je uspjesno pronaden!" << endl << endl;
	    return;
    }
    if(x > T->label){
	    if(ExistsRightChild(T)) 
			searchBT(x, T->right);
	    else 
			cout << "Trazeni element ne postoji!" << endl;;
    }
    if(x < T->label){
    	if(ExistsLeftChild(T)) 
			searchBT(x, T->left);
    	else 
			cout << "Trazeni element ne postoji!" << endl;;
    }	
}

Initial URL


Initial Description
Implementacija binarnog stabla pretraživanja iz kolegija Strukture podataka.

Initial Title
binarno stablo_pretraživanje

Initial Tags
podataka

Initial Language
C++