Ho buttato gių questo codice... ditemi cosa ne pensate e dove sono gli eventuali errori... Grazie!!!
Codice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
public struct TreeNode
{
int item; // The data in this node.
public TreeNode* left; // Pointer to the left subtree.
public TreeNode* right; // Pointer to the right subtree.
}
unsafe int countNodes(TreeNode* root)
{
// Count the nodes in the binary tree to which
// root points, and return the answer.
if (root == null)
return 0; // The tree is empty. It contains no nodes.
else
{
int count = 1; // Start by counting the root.
count += countNodes(root->left); // Add the number of nodes in the left subtree.
count += countNodes(root->right); // Add the number of nodes in the right subtree.
return count; // Return the total.
}
}
int Max(int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
unsafe int TreeDeep(TreeNode* root)
{
int l, r;
if (root == null)
{
return 0; // Tree is empty => TreeDeep = 0
}
else
{
l = TreeDeep(root->left); // Calculation of depth of left subtree
r = TreeDeep(root->right); // Calculate of depth of right subtree
return (Max(l, r)+1); // Tree's overall depth is > 1
}
}
unsafe int contNodeSameLevel(TreeNode* root, int h)
{
if (root == null)
{
return 0;
}
if (h == 0)
{
return 1;
}
else
{
return contNodeSameLevel(root->left, h - 1) + contNodeSameLevel(root->right, h - 1);
}
}
static void Main(string[] args)
{
}
}
}