guptaamitvidita
BAN USERI think the following algo will work though written in C#
/// <summary>
///
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public bool IsBST(Node node)
{
if (node == null)
return true;
else
{
if (!IsBSTUtil(node))
return false;
}
return true;
}
/// <summary>
/// /
/// </summary>
/// <param name="node"></param>
/// <param name="data"></param>
/// <returns></returns>
public bool IsBSTUtil(Node node)
{
if (node == null)
return true;
else
{
if (node.Left != null && node.Left.Data > node.Data)
return false;
if (node.Right != null && node.Right.Data <= node.Data)
return false;
if (!IsBSTUtil(node.Left) || !IsBSTUtil(node.Right))
return false;
}
return true;
}
public int[] MergeArray(int[] a, int[] b)
- guptaamitvidita June 04, 2010{
int marker;
marker = a.Length - b.Length;
int x = 0;
int i =0;
for (; i < a.Length-1; i++)
{
if (a[i] >= b[x])
{
int y=marker;
while (y > i)
{
a[y] = a[y - 1];
y--;
}
a[i] = b[x];
x++;
marker++;
}
}
while (x < b.Length)
{
a[marker] = b[x];
x++;
marker++;
}
return a;
}