//avl tree insertion and rotation
#include
#include
#include
#include
struct NODE{
char city[15];
int height;
struct NODE * left; // pointer untuk subtree kiri
struct NODE * right; // pointer untuk subtree kanan
struct NODE * back; // pointer untuk node parennya
};
typedef struct NODE NODE;
typedef NODE * node; // declarasi pointernya
//***********************************
// prototipe fungsinya
int Strcmp(char *, char *);
last=0;
while(found==0){
if (newptr==headptr) found=1;
if ((newptr->left==NULL))
{
if(newptr->right->height==2){
found=1;
rotate(newptr);
}
else
{
currentptr=newptr->back;
if(currentptr!=NULL)
{
if(currentptr->left==newptr){
way[last]=0;
last++;
}
else{
way[last]=1;
last++;
}
}
newptr=currentptr;
}
}
else if ((newptr->right==NULL)){
if(newptr->left->height==2){
found=1;
rotate(newptr);
}
else{
currentptr=newptr->back;
if(currentptr!=NULL){
if(currentptr->left==newptr){
int max(int value1, int value2)
{
return ( (value1 > value2) ? value1 : value2);
}
int height(node n)
{
if(n==NULL)
return 0;
else
n->height=1+max(height(n->left),height(n->right));
}
node FillNode(node gen,char * city)
{
gen=(node)malloc(sizeof(NODE));
strcpy(gen->city,city);
gen->height=0;
gen->left=NULL;
gen->right=NULL;
gen->back=NULL;
return gen;
}
selengkapnya kunjungi facebook(Note) saya :cahputri_box@yahoo.co.id
Tidak ada komentar:
Posting Komentar