@anush:
we should look at all descendants and ancestors. .. but u 'r looking at pars
....
In our structure we should have a parent pointer ..
and we should look at all our descendants --- takes O(n) time ..

correct me if I'm wrong ...

On Tue, Sep 20, 2011 at 10:54 AM, anshu mishra <[email protected]>wrote:

> for simplicity i am doing it for binary tree (liittle modification)
>
>
> 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->lockedDesc) 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.
>



-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar<http://www.google.com/profiles/bagana.bharatkumar>
*
Mobile +91 8056127652*
<[email protected]>

-- 
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