fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. int val;
  6. Test left;
  7. Test right;
  8.  
  9. public Test(int val)
  10. {
  11. this.val = val;
  12. }
  13.  
  14. public static bool IdenticalTrees(Test a, Test b)
  15. {
  16. if (a == null || b == null) {
  17. return true;
  18. }
  19.  
  20. if (a != null && a != null) {
  21. return (a.val == b.val && IdenticalTrees(a.left, b.left) && IdenticalTrees(a.right, b.right));
  22. }
  23.  
  24. return false;
  25. }
  26. public static void Main()
  27. {
  28. Test a = new Test(1);
  29. a.left = new Test(2);
  30. a.right = new Test(3);
  31. a.left.left = new Test(4);
  32. a.right.right = new Test(5);
  33.  
  34.  
  35. Test b = new Test(1);
  36. b.left = new Test(2);
  37. b.right = new Test(3);
  38. b.left.left = new Test(4);
  39. b.right.right = new Test(4);
  40.  
  41. Console.WriteLine(IdenticalTrees(a, b));
  42. }
  43. }
Success #stdin #stdout 0s 131648KB
stdin
Standard input is empty
stdout
False