Results 1 to 4 of 4
  1. #1
    tuckker is offline Member
    Join Date
    Dec 2007
    Posts
    4
    Rep Power
    0

    Question Retrieving out objects from Vector

    I have the following:

    Java 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):
    Java Code:
    queue.add(current.left);
    But if I do a:
    Java Code:
    node = queue.firstElement();
    , it gives me:
    Type 'custNode' is expected but 'E' found.

    How do I retrieve element out from the queue?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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;
        }
    }

  3. #3
    tuckker is offline Member
    Join Date
    Dec 2007
    Posts
    4
    Rep Power
    0

    Default

    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).

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    I thought you were using "rentVid" for the "left" and "right" CustNodes so I left it out.

Similar Threads

  1. JDO - Retrieving a persisted object
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-17-2008, 07:46 AM
  2. retrieving Properties
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 09:44 PM
  3. Vector containing heterogeneous objects
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-28-2007, 10:19 AM
  4. Retrieving data from the DB
    By yuchuang in forum JDBC
    Replies: 2
    Last Post: 11-27-2007, 08:59 AM

Posting Permissions

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