Results 1 to 3 of 3

Thread: trees??

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    2

    Question trees??

    How do you make an array based tree? I was asked to make a tree from an expression that will be inputted by the user and I have no clue how to go about this project!

  2. #2
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    what do you want to do exactly?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    chelle31 i am assuming that you are refering to a data structure such as a Vector or a TreeSet all of which can be found within java.util A TreeSet implements the SortedSet interface whereas a Vector implements the List interface. The difference between a List and a Set is that a List allows duplicates and maintains order whereas a Set does not allow duplicates and does not maintain order. So if you do not want duplicates and want to maintain order you would want to go with using a TreeSet which implements the SortedSet interface.

    As for your project did your teacher give you any additional information?

    For the time being here is an example of how to bridge the gap between arrays and Collections. Use the toArray() method found in the Collection interface and the asList() method found in theArray class.
    Code:
     
    Set tvset = new HashSet(Arrays.asList(xarray));
    String[] digitalarray = (String[]) tvset.toArray(new String[0]);

Posting Permissions

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



Click Here to Expand Forum to Full Width