Results 1 to 4 of 4
- 12-03-2007, 12:18 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 4
- Rep Power
- 0
Retrieving out objects from Vector
I have the following:
in my main program, I have custNode.left and .right stored in a vector using (queue is the vector):Java Code:class CustNode { int telNo; String name; Vector rentVid = new Vector(); CustNode left; CustNode right; }
But if I do a:Java Code:queue.add(current.left);
, it gives me:Java Code:node = queue.firstElement();
Type 'custNode' is expected but 'E' found.
How do I retrieve element out from the queue?
- 12-03-2007, 02:18 AM #2
Binary tree nodes don't need Collections. Try this:
Java 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; } }
- 12-03-2007, 03:30 AM #3
Member
- Join Date
- Dec 2007
- Posts
- 4
- Rep Power
- 0
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).
- 12-03-2007, 05:52 AM #4
Similar Threads
-
JDO - Retrieving a persisted object
By Java Tip in forum Java TipReplies: 0Last Post: 03-17-2008, 07:46 AM -
retrieving Properties
By bugger in forum New To JavaReplies: 1Last Post: 01-13-2008, 09:44 PM -
Vector containing heterogeneous objects
By Java Tip in forum Java TipReplies: 0Last Post: 11-28-2007, 10:19 AM -
Retrieving data from the DB
By yuchuang in forum JDBCReplies: 2Last Post: 11-27-2007, 08:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks