Results 1 to 2 of 2
  1. #1
    hjxlpp is offline Member
    Join Date
    May 2013
    Rep Power

    Question how to start the BreadthFirstTraverse using queue?

    Hi, Everyone. I am a newer at java programming. Now i have a assignment question is about:

    Look at the file: It contains one static method, called trav that must traverse a input object in breadth-first order, adding it's values to an ArrayList which is then returned as a result.

    All of the code in trav is missing. For this question, you must write this code. As an example of how the code should work when it is finished, the driver program: will output:

    [on, the, first, day, of, christmas, my, true, love]
    [the, day, of]

    when compiled and run with a properly implemented verion of trav in
    Random note about generics
    Note that the signature to trav has a formal type parameter immediately after the static keyword. Static methods can exist independently of instances of their encapsulating classes. Because of this independence, generic static methods have their own type parameters.

    Anyone can give me some tips about this question? Thanks very much!
    Java Code:
    import java.util.ArrayList;
    public class BreadthFirstDriver{
        public static void main(String [] args){
            BinTree<String> carol9 = new BinTree<String>(null,null,"love");
            BinTree<String> carol8 = new BinTree<String>(null,null,"true");
            BinTree<String> carol7 = new BinTree<String>(carol8,carol9,"my");
            BinTree<String> carol6 = new BinTree<String>(null,null,"christmas");
            BinTree<String> carol5 = new BinTree<String>(null,null,"of");
            BinTree<String> carol4 = new BinTree<String>(null,null,"day");
            BinTree<String> carol3 = new BinTree<String>(carol6,carol7,"first");
            BinTree<String> carol2 = new BinTree<String>(carol4,carol5,"the");
            BinTree<String> carol1 = new BinTree<String>(carol2,carol3,"on");
    Java Code:
    import java.util.ArrayList;
    public class BreadthFirstTraverse{
         * a method to traverse a BinTree in breadth-first order
           adding it's contents to an {@link ArrayList}.
           @param a binTree.
           @return an array list of the input tree's values.
        public static <T> ArrayList<T> trav(BinTree<T> t){
            // fill in the missing code

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: how to start the BreadthFirstTraverse using queue?

    Most breadth first methods start after pushing the root (of all evil) in the queue. The method runs until the queue is empty.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Job queue
    By ConradTSMITH in forum New To Java
    Replies: 0
    Last Post: 08-31-2012, 07:14 AM
  2. Replies: 0
    Last Post: 05-27-2011, 08:46 AM
  3. Replies: 1
    Last Post: 01-18-2011, 06:27 PM
  4. Replies: 5
    Last Post: 03-20-2009, 10:04 PM
  5. Queue in the GUI
    By jonywalker123 in forum Advanced Java
    Replies: 2
    Last Post: 03-06-2009, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts