Results 1 to 6 of 6

Thread: linked list- JAVA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    linked list- JAVA

    i was going through my java exercise and here is exercise that i did not get it. let me know if you know anything.

    suppose cursor refers to a node in a linked list (using the Node class with instance variables called data and link). What boolean expression will be true when cursor refers to the tail node of the list?

    a) (cursor==null)
    B) (cursor.link==null)
    c) (cursor.data==null)
    D) (cursor.data==0.0)
    E) none of the above

  2. #2
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: linked list- JAVA

    From my stock knowledge:

    I would say... B is the right answer.

    since it is not pointing to another NoDE element.

    node-> node -> node -> node(tail)

    A is wrong since
    node-> node -> node(actual tail) -> null... if i'm not mistaken there's a programming term for the type of problem for this one... it is not garbage though.
    C does not really tell anything because it only talks about the data. The node might have no data but the Link variable might be referencing another node.
    D again refer to explanation in C it should be more or less same explanation except in this case 0 is the value.


    That is, If I still remember my classes in OOP and Programming right.

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: linked list- JAVA

    A) or B) [not sure of the JAVA class]

    Singly-linked list

    The simplest kind of linked list is a singly-linked list (or slist for short), which has one link per node. This link points to the next node in the list, or to a null value or empty list if it is the last node.
    http://en.wikipedia.org/wiki/Linked_list

    ALSO THIS:
    Code:
     // source file link.java
    
            public class link {
                    public int value;              // value of element
                    public link next;              // reference to next
            
                    // constructor
                    public link(int n, link ln)
                    {
                            value = n;
                            next = ln;
                    }
    
                    public static void main(String args[])
                    {
                            // initialize list head
                            link head = null;
    
                            // add some entries to list
                            for (int i = 1; i <= 10; i++)
                                    head = new link(i, head);
    
                            // dump out entries
                            link p = head;
                            while (p != null) {
                                    System.out.println(p.value);
                                    p = p.next;
                            }
                    }
            }
    Last edited by dglienna; Sep 11th, 2005 at 11:58 PM.

  4. #4
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: linked list- JAVA

    Quote Originally Posted by dglienna
    A) or B) [not sure of the JAVA class]



    http://en.wikipedia.org/wiki/Linked_list
    thus it is B and no other, it does not say that the NODE be null, which in the case of A the cursor or node is null itself.

    In the definition it just says link will have a value null or empty.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: linked list- JAVA

    if i'm not mistaken there's a programming term for the type of problem for this one
    Well, if cursor is NULL then you have a past-the-end pointer.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    Re: linked list- JAVA

    thanks alot everyone. i think i have better idea how cursor works.

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