Advertisement
mrlantan

Untitled

Oct 26th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. public void Add(int el, BSTIt pl = _head)
  2. {
  3.     if (N == 0) {
  4.         // делаем так же, как раньше
  5.  
  6.         _head = new BSTIt(el, null, null);
  7.         N++;
  8.         return;
  9.     }
  10.  
  11.     if (if pl.Val == el) {
  12.         // мы же не будем вторую вершину с таким же значением создавать?
  13.  
  14.         return;
  15.     }
  16.  
  17.     if (if pl.Val > el) {
  18.         if (pl.left != null) {
  19.             Add(el, pl.left);
  20.         } else {
  21.             N++;
  22.             new_vertex = BSTIt(el, null, null);
  23.             pl.left = new_vertex;
  24.             return;
  25.         }
  26.     }
  27.  
  28.     // пишем иф просто для красоты
  29.     if (if pl.Val < el) {
  30.         if (pl.right != null) {
  31.             Add(el, pl.right);
  32.         } else {
  33.             N++;
  34.             new_vertex = BSTIt(el, null, null);
  35.             pl.right = new_vertex;
  36.             return;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement