خرید بک لینک

Vote count: 0

I am trying to traverse a doubly linked linked list but i seem to get an infinite loop. My goal is to find the first left most occurrence of an element in the list. I find the element but my program seems to keep looping. The only way to stop it from looping is breaking. There has to be another way. Thanks. {

    Node<E> temp;
    temp = head;

    while(temp.next != null){

        if(temp.value==obj){
            System.out.println("YES");
        }

        else{
            temp = temp.next;
        }

        System.out.println("nNO");
    }

}

asked 3 mins ago

1 Answer

Vote count: 0

You need to advance in any case. Swap printing "no" and the next assignment:

Node<E> temp;
temp = head;

while(temp != null){
    if(temp.value==obj){
        System.out.println("YES");
    } else {
        System.out.println("nNO");
    }
    temp = temp.next;
}

answered 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 22 فروردين 1395 ساعت: 6:01

صفحه بندی