#include #include #include struct element{ struct element *parent; int k; struct element *right; struct element *left; }; struct element *BST_wstaw(struct element *root,struct element *nowy); void inorder(struct element *root); int main(){ struct element *root=NULL; struct element *nowy=NULL; int liczba,i=0; while(i<5){ printf("Podaj lliczbe"); scanf("%d",&liczba); nowy = (struct element*)malloc(sizeof(struct wezel)); nowy->k=liczba; nowy->left=NULL; nowy->right=NULL; root=BST_wstaw(root,nowy); i++; } inorder(root); getch(); return 0; } struct element* BST_wstaw(struct element *root,struct element *nowy){ struct element* y= NULL,*x=root; while(x!=NULL){ y=x; if(x->k < nowy->k) x=x->right; else x=x->left; } nowy -> parent = y; if(y==NULL) root=nowy; else if(nowy->k < y-> k) y->left=nowy; else y->right=nowy; return root; } void inorder(struct wezel *root){ if(root!=NULL){ inorder(root->left); printf("%d ",root->k); inorder(root->right); } } struct element* usun(struct element *root,struct element *nowy) { struct element* y; if(nowy->left=NULL || nowy->right=NULL) y=nowy; else y=nastepnik(root); if(y->left!=NULL) x=y=>left; else x=y->right; if(x!=NULL) x->parent=y->parent; if y->p=NULL struct element* nastepnik(struct element*x) { struct element* y; if x->right!=NULL; return min(x->right); y=x->parent; while(y!=NULL && x==y->right) { x=y; y=y->parent; } return y; } struct element* min(struct element*x) { if (x->left==NULL) return x; else return min(x->left); }