Yuvalxp8 icon

BinTree_YuvalPorat

Yuvalxp8 | PRO | 02/17/18 04:41:52 PM UTC | 0 ⭐ | 465 👁️ | Never ⏰ | []
text |

1.54 KB

|

None

|

0 👍

/

0 👎

public static void InitialScan (BinNode<Integer> t)
	{
		if (t!=null)
		{
			System.out.println(t.getValue());
			InitialScan(t.getLeft());
			InitialScan(t.getRight());
		}
	}
 	public static void InnerScan(BinNode<Integer> t)
	{
		if(t!=null)
		{
			InnerScan(t.getLeft());
			System.out.println(t.getValue());
			InnerScan(t.getRight());
		}
	}
 	public static void FinalScan (BinNode<Integer> t)
	{
		if(t!=null)
		{
			FinalScan(t.getLeft());
			FinalScan(t.getRight());
			System.out.println(t.getValue());
		}
	}
 	public static void printEven(BinNode<Integer> t)
	{
		if(t!=null)
		{
			if(t.getValue()%2==0)
				System.out.println(t.getValue());
 			printEven(t.getLeft());
			printEven(t.getRight());
		}
	}
 	public static void printIfBiggerThanFather(BinNode<Integer> t)
	{
		int father = t.getValue();
		if(t!=null)
		{
			if(t.getValue() < father)
				System.out.println(t.getValue());
 			printIfBiggerThanFather(t.getLeft());
			printIfBiggerThanFather(t.getRight());
		}
	}
 	public static void printBiggerNodes (BinNode<Integer> t)
	{
		if(t!=null)
		{
			if(t.hasLeft() && t.hasRight())
			{
				if(t.getValue()>t.getLeft().getValue() || t.getValue()>t.getRight().getValue())
					System.out.println(t.getValue());
			}
			printBiggerNodes(t.getRight());
			printBiggerNodes(t.getLeft());
		}
	}
 	public static int Sum (BinNode<Integer> t)
	{
		int sum = 0; 
		if(t!=null)
		{
			sum += t.getValue();
			Sum(t.getLeft());
			Sum(t.getRight());
		}
		return sum;
	}

Comments