for simplicity i doing it for binary tree

struct node
{
     bool lock;
     int lockedDesc;
     node *left, *right, *par;
};

bool Islock(node *cur)
{
    return cur->bool;
}

void unLock(node *cur)
{
     node *temp;
     cur->lock = false;
     temp = cur->par;
     while (temp != NULL)
     {
             temp->lockedDesc--;
             temp = temp->par;
     }
}

bool Lock(node *cur)
{
     if (cur->anydesc) return false;
     node *temp = cur->par;
     while (temp != NULL && temp->lock== false)
     {
         temp->lockedDesc++;
         temp = temp->par;
     }
    if (temp == NULL)
    {
        cur->lock = true;
        return true;
    }
    cur = cur->par;
    while (cur != temp)
    {
        cur->lockedDesc--;
        cur= cur->par;
    }
    return false;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to