Shiva
BAN USERbool check(Tree *root,int currlevel,int *prevLeaflevel)
{
if(currlevel > prevLeaflevel && prevLeafLevel > 0)
{
return 0;
}
if(root->left == NULL && root->right == NULL)
{
// If leaf node check then check the previous leaf level
if(*prevLeaflevel == 0)
{
// If this is the first leaf
*prevLeaflevel = currlevel;
}
if(currlevel == prevLeaflevel)
{
return 1;
}
else
{
return 0;
}
}
bool b1 = 1;
bool b2 = 1;
if(root->left != NULL)
{
b1 = check(root->left,currlevel+1,&prevLeafLevel);
}
if(b1 && root->right != NULL)
{
b2 = check(root->right,currlevel+1,&prevLeafLevel);
}
return(b1 & b2);
}
Call :
prevleafLevel = 0;
check(root,0,&prevleafLevel);
Call func(arr,5,0,1);
void func(char arr[],int n,int i,int j)
{
if(i == n - 1)
{
return;
}
for(k = 0;k< n;k++)
{
if(k != i && k != j)
{
arr[k] = 'b';
}
else
{
arr[k] = 'a';
}
}
for(k= n - 1;k >= 0;k--)
{
// The bytes initialised with 'a' remain unchanged.
if(k == i || k == j)
{
continue;
}
while(arr[k] <= 'z')
{
// print the arr
print(arr);
++arr[k];
}
--arr[k];
}
// If second 'a' reaches the end Start moving first 'a'
if(j == n-1)
{
i++;
j= i+1;
}
else
{
j++;
}
func(arr,n,i,j);
}
- Shiva November 23, 2013