Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void PreOrder_Ricorsivo(BST T, Action<BST> Action_PreOrder)
- {
- if (T != null)
- {
- Action_PreOrder(T);
- PreOrder_Ricorsivo(T.Sx, Action_PreOrder);
- PreOrder_Ricorsivo(T.Dx, Action_PreOrder);
- }
- }
- public static void InOrder_Ricorsivo(BST T, Action<BST> Action_InOrder)
- {
- if (T != null)
- {
- InOrder_Ricorsivo(T.Sx, Action_InOrder);
- Action_InOrder(T);
- InOrder_Ricorsivo(T.Dx, Action_InOrder);
- }
- }
- public static void PostOrder_Ricorsivo(BST T, Action<BST> Action_PreOrder, Action<BST> Action_InOrder, Action<BST> Action_PostOrder)
- {
- if (T != null)
- {
- Action_PreOrder(T);
- PostOrder_Ricorsivo(T.Sx, Action_PreOrder, Action_InOrder, Action_PostOrder);
- Action_InOrder(T);
- PostOrder_Ricorsivo(T.Dx, Action_PreOrder, Action_InOrder, Action_PostOrder);
- Action_PostOrder(T);
- }
- }
- public static void PreOrder_Iterativo(BST T, Action<BST> Action_PreOrder)
- {
- var S = new Stack<BST>();
- while (S.Count > 0 || T != null)
- if (T != null)
- {
- Action_PreOrder(T);
- S.Push(T);
- T = T.Sx;
- }
- else
- {
- T = S.Peek();
- T = T.Dx;
- S.Pop();
- }
- }
- public static void PostOrder_Iterativo(BST T, Action<BST> Action_PreOrder, Action<BST> Action_InOrder, Action<BST> Action_PostOrder)
- {
- BST last = null;
- var S = new Stack<BST>();
- while (S.Count > 0 || T != null)
- if (T != null)
- {
- Action_PreOrder(T);
- S.Push(T);
- T = T.Sx;
- }
- else
- {
- T = S.Peek();
- if (T.Dx != null && T.Dx != last)
- {
- Action_InOrder(T);
- T = T.Dx;
- }
- else
- {
- Action_PostOrder(T);
- last = T;
- T = null;
- S.Pop();
- }
- }
- }
- public static void InOrder_Iterativo(BST T, Action<BST> Action_InOrder)
- {
- var S = new Stack<BST>();
- while (S.Count > 0 || T != null)
- if (T != null)
- {
- S.Push(T);
- T = T.Sx;
- }
- else
- {
- T = S.Pop();
- Action_InOrder(T);
- T = T.Dx;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement