0

My method is not working for some reason, even though i have done in exactly the same way the books showed.
Could you please take a look at it and let me know what went wrong?
Thank you
P.S. I tried to use DEBUG technique and it seems that the method doesn't even go through the list.

public static IntNode listSearch(IntNode head, int target) {

        IntNode cur;

        for (cur = head; cur != null; cur = cur.link) 
            if (target == cur.data){
                System.out.println("DEBUG" + cur.data);
            }
            else
              System.out.println("DEBUG" + null); 
        return null;

}

this is how i call my method in main my.listSearch(null, 21); // method does not work

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by grisha83
0

My method is not working for some reason, even though i have done in exactly the same way the books showed.
Could you please take a look at it and let me know what went wrong?
Thank you
P.S. I tried to use DEBUG technique and it seems that the method doesn't even go through the list.

public static IntNode listSearch(IntNode head, int target) {

        IntNode cur;

        for (cur = head; cur != null; cur = cur.link) 
            if (target == cur.data){
                System.out.println("DEBUG" + cur.data);
            }
            else
              System.out.println("DEBUG" + null); 
        return null;

}

this is how i call my method in main my.listSearch(null, 21); // method does not work

As per my knowledge, I think you should not check objects against null.... Problem with for loop..

0

As per my knowledge, I think you should not check objects against null.... Problem with for loop..

You are right!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.