לשאלה המלאה לחצו כאן

סעיף א' בשפת java

public static void mirror (BinNode<Integer> t)
{

        if(t==null)

                return ;

        // channing sons

        BinNode<Integer> temp = t.getLeft();

        t.setLeft( t.getRight()  );

        t.setRight(temp);

mirror (t.getLeft());

mirror (t.getRight());

}

סעיף א' בשפת C#

public static void Mirror (BinNode<int> t)
{

        if(t==null)

                return ;

        // channing sons

        BinNode<int> temp = t.GetLeft();

        t.SetLeft( t.GetRight()  );

        t.SetRight(temp);

Mirror (t.GetLeft());

Mirror (t.GetRight());

}

סעיף   ב' שפת java

נכתוב פעולת עזר המקבלת שני עצים ומחזירה אמת אם הם זהים (מבחינת ערכיהם), אחרת שקר.

public static boolean isSame(  BinNode<Integer> t1 , BinNode<Integer> t2  )

{

        if(t1 == null && t2==null)

                return true;

        // one of them is null

        if(t1== null || t2 == null)

                return false;

        if( t1.getValue() != t2.getValue())

                return false;

        

        return isSame(t1.getLeft(),t2.getLeft()) && isSame(t1.getRight(),t2.getRight());

}

הפונקציה העיקרי של סעיף ב' שפת java

public static boolean isMirror(BinNode<Integer> t1 , BinNode<Integer> t2)

{

return isSame(    t1 , mirror(t2) );

}

סעיף   ב' שפת C#

נכתוב פעולת עזר המקבלת שני עצים ומחזירה אמת אם הם זהים (מבחינת ערכיהם), אחרת שקר.

public static bool IsSame(  BinNode<int> t1 , BinNode<int> t2  )

{

        if(t1 == null && t2==null)

                return true;

        // one of them is null

        if(t1== null || t2 == null)

                return false;

        if( t1.GetValue() != t2.GetValue())

                return false;

        

        return IsSame(t1.GetLeft(),t2.GetLeft()) && IsSame(t1.GetRight(),t2.GetRight());

}

הפונקציה העיקרי של סעיף ב' שפת C#

public static bool IsMirror(BinNode<int> t1 , BinNode<int> t2)

{

return IsSame(    t1 ,Mirror(t2) );

}