How do i implement a Queue using a BST.
Is this the way to do it, keep on inserting the nodes in the tree while maintaining a count value associated with each and every node,but while deletion BST should work like queue(FIFO) so start deleting from BST with the node having lowest count value in the tree.
Did i get the question and solution right? If not,then please explain me the question.
You can have a Queue like this:
You add to the nodes structs of BST also a pointer to another node that will represent the order of insertion.
During the insertion
When you want to add an element, you first access the node that the pointer tail points to and make it point to the new element that you just inserted (the BST node). Then you update the tail pointer to point to the new element.
During the deletion
When you remove an element, you first access the node that the head pointer points to, you store the
next_queune_elementin an auxiliary temporary variable and remove the node. Finally, make the head pointer to point to the auxiliary temporary variable.