|
-
Sep 11th, 2005, 11:28 PM
#1
Thread Starter
Junior Member
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
-
Sep 11th, 2005, 11:38 PM
#2
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.
-
Sep 11th, 2005, 11:53 PM
#3
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.
-
Sep 12th, 2005, 01:44 AM
#4
Re: linked list- JAVA
 Originally Posted by dglienna
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.
-
Sep 12th, 2005, 03:41 AM
#5
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.
-
Sep 12th, 2005, 09:37 AM
#6
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|