Dinesh
BAN USER
Questions (2)
Comments (3)
Reputation 195
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
class node
{
int vals[N-1];
node children[N];
node parent;
}
Add one extra member for node structure "Node *Parent"
Write a function which takes node and it's parent as args.
Find_Loop(Node *root, Node *Par) //par=NULL for root node
{
if ( root->parent != par )
{
print "Loop found";
exit;
}
//visit the node
for(int i=0;i<N && root[i+1]!=NULL ;i++)
Find_Loop( root->children[i], root);
}
For every recursive call we will pass child node and current node(as parent) as args.
Please correct me if anything is wrong.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Here is working c++ code:
- Dinesh November 18, 2013void reverse_chunks(int a[],int size, int chunk)
{
int index=0;
for(int i=0;i<size/chunk;index+=chunk,++i)
reverse_chunk(a,index,index+chunk-1);
if(index<size)
reverse_chunk(a,index,size-1);
}