turix
turix

Reputation: 31

Sorted Doubly linked circular list // java

I have a problem with finding elements in Sorted Doubly Linked circular list. I need to find count of values in list that are between 0 and 10. // [0;10]. The problem is that it doesn't allow me to ask for itv() from main class.

case 2 :
   System.out.println("[0;20] = "+ list.itv() +" \n");
   break;

it shows error. How can i fix that?

    public void itv (){
        Node ptr = start;
        int size=0;
        size = getSize();
        int c = 0;
        while (size != 0){
            if(ptr.getData() >=0 && ptr.getData() <=20) {
                c++;
            }
            ptr = ptr.getLinkNext();
            size--;
        }
        System.out.println("[0;20] = " + c);
    }

Upvotes: 0

Views: 76

Answers (1)

MiltoxBeyond
MiltoxBeyond

Reputation: 2731

Your function returns void. Either return a string like so:

public string itv()
{
  Node ptr = start;
        int size=0;
        size = getSize();
        int c = 0;
        while (size != 0){
            if(ptr.getData() >=0 && ptr.getData() <=20) {
                c++;
        }
        ptr = ptr.getLinkNext();
        size--;
        }
        //This line changes
        return "[0;20] = " + c;
}

OR in the main print before and after calling like so, and without doing the above change:

System.out.print("[0;20] = ");
list.itv(); //List.itv() still has System.out.println(...)
break;

Upvotes: 1

Related Questions