-1

I'm trying to convert a function that i had that quickSorted an array into a vector quicksort function. I keep getting this cannot find symbol. This is my function that im trying to adapt into vector quickSort

public static void quickSort(Vector<Personne> arr, int low, int high, Personne[] pers) {
    if (arr.isEmpty() == true || arr.size()== 0)
        return;

    if (low >= high)
        return;

    int middle = low + (high - low) / 2;
    int pivot = arr.get(middle).getNumero();
    int i = low, j = high;

    while (i <= j) {
        while (arr.get(i).getNumero() < pivot) {
            i++;
        }

        while (arr.get(j).getNumero() > pivot) {
            j--;
        }

        if (i <= j) {
            Vector<Personne> temp = new Vector<Personne>();
            temp.add(arr.get(i));
            arr.get(i).add(arr.get(j));

            i++;
            j--;
        }
    }

    if (low < j)
        quickSort(arr, low, j, pers);

    if (high > i)
        quickSort(arr, i, high, pers);
}

This part of the function is giving me errors:

if (i <= j) {
    Vector<Personne> temp = new Vector<Personne>();
    temp.add(arr.get(i));
    arr.get(i).add(arr.get(j));
    i++;
    j--;
}

I tried .get() ,.elementAt() ,creating a new temp vectors that will hold the information but I just can't seem to fix it.

error

C:\Users\Arnold\Desktop\numero3.java:241: error: cannot find symbol arr.get(i).add(arr.get(j)); ^ symbol: method add(Personne) location: class Personne 1 error

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
  • what is error you get? – Kick Buttowski Nov 10 '14 at 00:54
  • and that if clause, do you exchange anything? I think not – Kick Buttowski Nov 10 '14 at 00:56
  • give me a symbol error – user3268216 Nov 10 '14 at 00:56
  • 2
    Not with that tone... Paste your stacktrace. – Mr. Polywhirl Nov 10 '14 at 00:57
  • im sorry if i offended anyone. But what is a stacktrace? – user3268216 Nov 10 '14 at 00:58
  • 2
    It's a joke, I guess you meant *"[It keeps] giv[ing] me a symbol error."* Anyways, paste the error that gets spit from the console out when you try to compile. ***[What is a Stacktrace?](http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors)***. – Mr. Polywhirl Nov 10 '14 at 01:00
  • i believe it is this? C:\Users\Arnold\Desktop\numero3.java:241: error: cannot find symbol arr.get(i).add(arr.get(j)); ^ symbol: method add(Personne) location: class Personne 1 error – user3268216 Nov 10 '14 at 01:04
  • 1
    If `Personne` is in another package or directory, you need to import it. Throw in this line at the top; after your package (if applicable) `import {path.to}.Personne;`... Of course, the placeholder "`{path.to}`" is the package where that class exists. See: ***[Importing packages in Java](http://stackoverflow.com/questions/12248906/importing-packages-in-java)*** – Mr. Polywhirl Nov 10 '14 at 01:06
  • your issue is **not reproducible** so I think It can be flagged as **off topic** question – Kick Buttowski Nov 10 '14 at 01:07
  • personne is a class that i created to read a .txt file and convert each line into the object array – user3268216 Nov 10 '14 at 01:07
  • thx. i fixed it. i replaced it with Personne o=arr.elementAt(i); arr.setElementAt(arr.elementAt(j),i); arr.setElementAt(o,j); i++; j--; – user3268216 Nov 10 '14 at 01:14

2 Answers2

0

Base on this snippet code from Program: Implement quick sort in java.

private void exchangeNumbers(int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }

you are exchanging element in i index with element in j index , so it seems you forget to put value of temp to j index of arrvector

if (i <= j) {
    Vector<Personne> temp = new Vector<Personne>();
    temp.add(arr.get(i));
    arr.get(i).add(arr.get(j));
    arr.add(temp.get(j)); <--------forget this line
    i++;
    j--;
}

Note: Your Personne class does not have add method

When a Java program is being compiled the compiler creates a list of all the identifiers in use. If it can't find what an identifier refers to (e.g., there is no declaration statement for a variable) it cannot complete the compilation. This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute.

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
  • oh sorry but i removed that line by accident. let me put it back. but even with that input it still keeps giving me error: cannot find symbol – user3268216 Nov 10 '14 at 01:03
0

error: cannot find symbol [...] symbol: method add(Personne) location: class Personne

This error is telling you that your Personne class does not have an add(Personne) method. This does not seem to be an import issue, as has been suggested in comments, because it seems you're using Personne objects elsewhere in your code without problem.

So, the issue is either that you don't have an add(Personne) method on your Personne class at all, in which case (seemingly questionable design practice aside) you need to add one. Or, and this is my guess, you do have an add(Personne) method on that class but it's either private (so other classes cannot find that symbol), or it's package-private (i.e. it has no access modifier) and you're attempting to access it from a class in another package, in which case, again, that class cannot find that symbol

drew moore
  • 31,565
  • 17
  • 75
  • 112
  • thx. i fixed it by replacing it with Personne o=arr.elementAt(i); arr.setElementAt(arr.elementAt(j),i); arr.setElementAt(o,j); i++; j--; – user3268216 Nov 10 '14 at 01:14