Advertisement
mikymaione

ESAME_ASD_20170224_03

May 13th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. public static int Algo_Miky(BST Tree, BST Dad, BST Node, int x)
  2. {
  3.     BST last = null;
  4.     var S = new Stack<BST>();
  5.     var R = new Stack<int>();
  6.     var ret = 0;
  7.  
  8.     while (S.Count > 0 || Node != null)
  9.         if (Node != null)
  10.         {
  11.             R.Push(1);
  12.             S.Push(Node);
  13.             Node = Node.Sx;
  14.         }
  15.         else
  16.         {
  17.             Node = S.Peek();
  18.  
  19.             if (Node.Dx != null && Node.Dx != last)                    
  20.                 Node = Node.Dx;                    
  21.             else
  22.             {
  23.                 ret = R.Pop();
  24.                 R.Push(ret + (R.Count > 0 ? R.Pop() : 0));
  25.                
  26.                 funzione(Tree, Node, Dad, x, ret);             
  27.  
  28.                 last = Node;
  29.                 Node = null;
  30.                 S.Pop();
  31.             }
  32.         }
  33.  
  34.     return ret;
  35. }
  36.  
  37. private static void funzione(BST Tree, BST Node, BST Dad, int x, int ret)
  38. {
  39.     if (Node.key % 2 == 0 && ret < x && Dad != null)
  40.     {
  41.         if (Node == Dad.dx)
  42.             Dad.dx = Cancella(Tree, Node);
  43.         else
  44.             Dad.sx = Cancella(Tree, Node);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement