Re: [algogeeks] classic problem to tree to circular doubly linked list

2012-05-28 Thread Ashish Goel
//can be improved by having a function to join 2 DLLs

struct node *tree2DLL(struct node * pRoot)
{
  if (!pRoot) return NULL;
  struct node *pleftDLL = tree2DLL(pRoot-left);
  struct node *pRightDLL = tree2DLL(pRoot-right);
 //now join left with root

 pLeftDLL-left-right = pRoot;
 pRoot-left = pleftDLL-left;
 pRoot-right= pLeftDLL;
 pLeftDLL-left = pRoot;

//now join pLeftDLL and pRightDLL;
  struct node* pTemp = pRightDLL-left;
  pLeftDLL-left-right = pRightDLL;
  pRightDLL-left = pLeftDLL-left;
  pTemp-right = pLeftDLL;
  pLeftDLL-left = pTemp;

  return pLeftDLL;


}
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Thu, May 24, 2012 at 11:20 PM, rahul r. srivastava 
rahul.ranjan...@gmail.com wrote:

 hey people

 can anyone explain the logic and solution(in simple words) behind the
 classical problem of converting binary tree to circular doubly linked list
 in inorder fashion.

  stanford language seems to be way above my head
 http://cslibrary.stanford.edu/109/TreeListRecursion.html

 thnx...

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/IyQsfiqEmdUJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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



Re: [algogeeks] classic problem to tree to circular doubly linked list

2012-05-24 Thread sanjay pandey
the main code is dis function only:i will explain dis

static Node treeToList(Node root) {
Node aList, bList;

if (root==NULL) return(NULL);*
/* the below next two lines are just lyk inorder traversal...u mst
hv done dis*/*
aList = treeToList(root-small);
bList = treeToList(root-large);

*/* this is for breaking the links of its left n right child nodes
n pointing to itself*/*
root-small = root;
root-large = root;

   * /* Appending leftchild parent n rightchild together in
doublylinked list form */*
aList = append(aList, root);
aList = append(aList, bList);

return(aList);
}

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