java LinkedList problem........plz have a look and tell me the reason
Code :
public class LinkedList
{
static Node start,end;
public static void main(String... args)
{
toNode(args);
}
static void toNode(String... arr)
{
end=start=new Node(Integer.parseInt(arr[0]));
Node p=start;
for(int i=1;i<arr.length;i++)
{
p.next=new Node(Integer.parseInt(arr[i]));
System.out.println(arr[i]+"inserted at "+p.next);
}
System.out.println("-------------------\nlocation of start: "+start);
System.out.println("location of start.next: "+start.next);
System.out.println("location of end: "+end+"\n\n");
//-------------------problem-----------------------------
System.out.println("And output of traversing is: \n");
for (p = start; p != null; p = p.next)
{
System.out.println(p.data);
}
//---------------------------------------------------------
}
}
class Node
{ int data;
Node next;
Node(int data)
{
this.data=data;
}
}
and output is:
45inserted at Node@3e25a5
78inserted at Node@19821f
23inserted at Node@addbf1
45inserted at Node@42e816
19inserted at Node@9304b1
24inserted at Node@190d11
687inserted at Node@a90653
47inserted at Node@de6ced
-------------------
location of start: Node@c17164
location of start.next: Node@de6ced
location of end: Node@c17164
And output of traversing is:
12
47
plz tell me why it is having only two node and it is not behaving like a LinkedList according to me there is no problem..................plz tell me
Re: java LinkedList problem........plz have a look and tell me the reason
I moved this thread: http://www.javaprogrammingforums.com...e-posting.html
Have you stepped through this with a debugger, or at the very least added some print statements, to figure out what's going on? When does the flow of the program differ from what you expect?
Re: java LinkedList problem........plz have a look and tell me the reason
Also, don't post multiple copies of the same question. That doesn't increase your chances of getting help. I've deleted your duplicate thread.
Re: java LinkedList problem........plz have a look and tell me the reason
Add some more printlns to show the values of ALL the variables that are used in the code when you are changing the values. If you print them all out, you will see the problem.