Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

compare two binary tree

public bool IsEqual(Node first, Node second)
{
    if (first == null && second == null) return true;

    if(first != null && second != null)
    {
      return first.data == second.data && 
          IsEqual(first.rightChild,second.rightChild) &&
          IsEqual(first.leftChild,second.leftChild);
    }
    return false;
}


// Node structure

public class Node
{
    private int data;
    private Node leftChild;
    private Node rightChild;
    public Node(int data)
    {
      	this.data = data;
    }
}
 
PREVIOUS NEXT
Tagged: #compare #binary #tree
ADD COMMENT
Topic
Name
9+9 =