------------------------budowa list posortowanej struct lista{ int info; struct list *next; } list -> NULL; if (list == NULL){ new(list, a); list -> info = a; list -> next = null; } else{ if(list->infro >a){ new(tmp, a); tmp -> info = a; tmp -> next = list; list = tmp; } else{ tmp = list; while(tmp->next!=null & tmp->next->info < a){ tmp = tmp -> next; } new(tmp2, a); tmp2->info = a; tmp2->next = tmp -> next; tmp -> next = tmp2; } } ------------------------------------------------------------------- struct tree { int info; struct tree *left; struct tree *right; }; --------------------------------------------------budowa drzewa struct tree *insert(struct tree *root, int x) { if(!root) { root=(struct tree*)malloc(sizeof(struct tree)); root->info = x; root->left = NULL; root->right = NULL; return(root); } if(root->info > x) root->left = insert(root->left,x); else { if(root->info < x) root->right = insert(root->right,x); } return(root); } ------------------------------- może się przydac do szukania ale trzeba przerobić struct tree *search(struct tree *root, int x) { struct tree *ptr; ptr=root; while(ptr) { if(x>ptr->info) ptr=ptr->right; else if(xinfo) ptr=ptr->left; else break; } ------------------------------- 3 porządki przechodzenia drzew / usuwanie podobnie jak postorder void inorder(struct tree *root) { if(root != NULL) { inorder(root->left); printf(" %d",root->info); inorder(root->right); } return; } void postorder(struct tree *root) { if(root != NULL) { postorder(root->left); postorder(root->right); printf(" %d",root->info); } return; } void preorder(struct tree *root) { if(root != NULL) { printf(" %d",root->info); preorder(root->left); preorder(root->right); } return;