Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 01:18 AM
Member
 
Join Date: Dec 2007
Posts: 4
tuckker is on a distinguished road
Retrieving out objects from Vector
I have the following:

Code:
class CustNode { int telNo; String name; Vector rentVid = new Vector(); CustNode left; CustNode right; }
in my main program, I have custNode.left and .right stored in a vector using (queue is the vector):
Code:
queue.add(current.left);
But if I do a:
Code:
node = queue.firstElement();
, it gives me:
Type 'custNode' is expected but 'E' found.

How do I retrieve element out from the queue?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 03:18 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Binary tree nodes don't need Collections. Try this:
Code:
public class CustNodeTest { public static void main(String[] args) { String[] names = { "John", "Carol", "Sue", "Bill", "Alice" }; int[] nums = { 1412, 3927, 1815, 2219, 1588 }; CustNode root = null; for(int j = 0; j < names.length; j++) { root = addNode(root, names[j], nums[j]); } System.out.println(root.getInOrderSort()); } private static CustNode addNode(CustNode node, String name, int n) { if(node == null) node = new CustNode(name, n); else if(name.compareTo(node.name) < 0) node.left = addNode(node.left, name, n); else node.right = addNode(node.right, name, n); return node; } } class CustNode { int telNo; String name; CustNode left; CustNode right; // Vector rentVid = new Vector(); CustNode() { this("", 0); } CustNode(String name, int telNo) { this(name, telNo, null, null); } CustNode(String name, int telNo, CustNode left, CustNode right) { this.name = name; this.telNo = telNo; this.left = left; this.right = right; } public String toString() { return "CustNode[name:" + name + " telNo:" + telNo + "]"; } public String getInOrderSort() { String s = ""; if(left != null) s += left.getInOrderSort() + " "; s += this + " "; if(right != null) s += right.getInOrderSort() + " "; return s; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2007, 04:30 AM
Member
 
Join Date: Dec 2007
Posts: 4
tuckker is on a distinguished road
Hey thanks for your response.

The node need to store the video ID that the customer has rented, and I am using vector to store the video ID to the node with the customer tel and name. A customer node can have a few rent ID (rent a few videos at the same time). However I do not find the video ID as part of your code...? (Correct me if I'm wrong).
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2007, 06:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
I thought you were using "rentVid" for the "left" and "right" CustNodes so I left it out.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDO - Retrieving a persisted object Java Tip Java Tips 0 03-17-2008 08:46 AM
retrieving Properties bugger New To Java 1 01-13-2008 10:44 PM
Vector containing heterogeneous objects Java Tip Java Tips 0 11-28-2007 11:19 AM
Retrieving data from the DB yuchuang Database 2 11-27-2007 09:59 AM
Retrieving serialized objects from file JavaForums Java Blogs 0 11-07-2007 10:03 PM


All times are GMT +3. The time now is 02:53 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org