Convert a binary search tree into in order doubly linked list
Void bst2dllIn (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
Bst2dllIn (root.left, ref head);
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
Bs2dllIn (root.right, ref head);
}
Convert a binary search tree into pre order doubly linked list
Void bst2dllPre (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
Bst2dllPre(root.left, ref head);
Bs2dllPre(root.right, ref head);
}
Convert a binary search tree into postorder doubly linked list
Void bst2dllPost (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
Bst2dllPost (root.left, ref head);
Bs2dllPost (root.right, ref head);
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
}
Void bst2dllIn (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
Bst2dllIn (root.left, ref head);
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
Bs2dllIn (root.right, ref head);
}
Convert a binary search tree into pre order doubly linked list
Void bst2dllPre (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
Bst2dllPre(root.left, ref head);
Bs2dllPre(root.right, ref head);
}
Convert a binary search tree into postorder doubly linked list
Void bst2dllPost (node root, ref node head)
{
If (root==null) { return}
Node prev =null;
Bst2dllPost (root.left, ref head);
Bs2dllPost (root.right, ref head);
If (prev == null)
Head = root;
Prev = root;
Else{
Root.prev = prev;
Prev.next = root;
Prev = root;
}
}
No comments:
Post a Comment