/// <summary> /// Returns an iterator over the search tree elements using /// the specified traversal to find elements. /// </summary> /// <param name="the_traversal_method">a traversal method to /// retrieve elements from the search tree.</param> /// <returns>an array representation of the search tree elements.</returns> public Iterator <T> iterator(GraphTraversals the_traversal_method, T the_source_node) { BinaryNode <T> node = getNode(the_source_node); Preconditions.checkNull(node); return(new BSTIterator <T>(the_traversal_method, node, this)); }
public GraphIterator(GraphTraversals the_traversal_method, Vertex <T> the_parent_root, DirectedGraph <T> the_parent) { /*my_traversal_method = the_traversal_method; * my_parent = the_parent; * * //prepare stack for traversal * my_elements = new Stack<BinaryNode<T>>(my_parent.size()); * * //add the first element if it is there * if (my_parent.my_root != null) * { * my_elements.push(my_parent.my_root); * }*/ }
/// <summary> /// Sets up the iterate with a traversal method, an initial node to traverse from and a link /// to the parent binary search tree. /// </summary> /// <param name="the_traversal_method">the method of traversing the tree.</param> /// <param name="the_parent_root">the root of the tree.</param> /// <param name="the_parent">link to the parent tree itself.</param> public BSTIterator(GraphTraversals the_traversal_method, BinaryNode <T> the_source_node, BinarySearchTree <T> the_parent) { my_traversal_method = the_traversal_method; my_parent = the_parent; //prepare stack for traversal my_element_stack = new Stack <BinaryNode <T> >(my_parent.size()); my_element_queue = new Queue <BinaryNode <T> >(); //add the first element if it is there if (my_parent.root != null) { my_element_stack.push(the_source_node); my_element_queue.enqueue(the_source_node); } }
/// <summary> /// Gives an iterator that will traverse the graph according to a traversal /// method. /// </summary> /// <param name="the_traversal_method">the traversal method.</param> /// <returns>an iterator.</returns> public Iterator <T> iterator(GraphTraversals the_traversal_method, T the_source_vertex) { return(new GraphIterator <T>(the_traversal_method, getVertex(the_source_vertex), this)); }
/// <summary> /// Returns an iterator over the search tree elements using /// the specified traversal to find elements. /// </summary> /// <param name="the_traversal_method">a traversal method to /// retrieve elements from the search tree.</param> /// <returns>an array representation of the search tree elements.</returns> public Iterator <T> iterator(GraphTraversals the_traversal_method) { return(new BSTIterator <T>(the_traversal_method, my_root, this)); }