Advertisement
patryk

Untitled

Apr 2nd, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. void add(el_bst * drzewo, int n, char c[], char d[])
  2. {
  3.     el_bst *nowy, *y=NULL, *x=root;
  4.     nowy=malloc(sizeof(el_bst));
  5.     nowy->nrindeksu=n;
  6.     strcpy(nowy->imie,c);
  7.     strcpy(nowy->nazwisko,d);
  8.     nowy->left=nowy->right=NULL;
  9.  
  10.     while (x)
  11.     {
  12.         y=x;
  13.         x= (nowy->nrindeksu<x->nrindeksu) ? x->left : x->right;
  14.     }
  15.  
  16.     nowy->p=y;
  17.     if(!y) {root=nowy;}
  18.     else if (nowy->nrindeksu < y->nrindeksu)
  19.     {
  20.         y->left=nowy;
  21.     }
  22.     else y->right=nowy;
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement