lossy conversion when dividing (long to int)

nugh

I am trying to find the middle index in an array (of type long) The problem im solving specifically asks for a long to return, so I cant change the signature I want to find the pivot point, in my quicksort code, but I get an error "possible lossy conversion from long to int" I understand that I may lose some information when dividing, but I want to bypass it here is the code containing the error:

public static long partition(long[] array, long left, long right){
    long i = left, j = right;
    long tmp;
    long pivot = array[(left + right) / 2];  // <-----ERROR HERE  <------

    while(i <= j) {
        while(array[i] < pivot){
        i--;
       }
       while(array[j] > pivot) {
           j--;
       }
       if(i <= j) {
           tmp =array[i];
           array[i] = array[j];
           array[j] = tmp;
           i++;
           j--;
       }
       }
    return i;
}
Heng Lin

use "array[index]", this "index" must be int. so

long pivot = array[(int)((left + right) / 2)];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Possible Lossy conversion from long to int

From Dev

Possible lossy conversion from long to int, JAVA

From Dev

possible lossy conversion from int to short

From Dev

Possible lossy conversion from double to int

From Dev

possibly lossy conversion from int to byte

From Dev

Java - possible lossy conversion from int to byte

From Dev

possible lossy conversion from int to short

From Dev

Java Possible Lossy Conversion Double to Int

From Dev

Conversion between long* and int* when sizeof(long) == sizeof(int)

From Dev

Java JDK - possible lossy conversion from double to int

From Dev

error: incompatible types: possible lossy conversion from double to int

From Dev

Compilation error. lossy conversion from double to int

From Dev

(Math.random() * a); possible lossy conversion from double to int

From Dev

long to int conversion in java not working

From Java

Inconsistent "possible lossy conversion from int to byte" compile-time error

From Dev

Double array method error: Incompatible types: possible lossy conversion from double to int

From Dev

Inconsistent "possible lossy conversion from int to byte" compile-time error

From Dev

Why I get an error? error: incompatible types: possible lossy conversion from double to int

From Dev

Least lossy file conversion for PDF

From Dev

Is conversion int -> unsigned long long defined by the standard

From Dev

Why doesn't clang warn about implicit conversion from double to int, but do it when from long to int?

From Dev

Double to Int without lossy precision

From Dev

Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

From Dev

Possible lossy from int to char; Occurs when reading in from a text file

From Dev

Type conversion: signed int to unsigned long in C

From Dev

Why is implicit conversion from int to Long not possible?

From Dev

C++ Is conversion from int to long a promotion?

From Dev

Java - possible lossy conversion from byte to char

From Dev

Problems with using float "possible lossy conversion"

Related Related

  1. 1

    Possible Lossy conversion from long to int

  2. 2

    Possible lossy conversion from long to int, JAVA

  3. 3

    possible lossy conversion from int to short

  4. 4

    Possible lossy conversion from double to int

  5. 5

    possibly lossy conversion from int to byte

  6. 6

    Java - possible lossy conversion from int to byte

  7. 7

    possible lossy conversion from int to short

  8. 8

    Java Possible Lossy Conversion Double to Int

  9. 9

    Conversion between long* and int* when sizeof(long) == sizeof(int)

  10. 10

    Java JDK - possible lossy conversion from double to int

  11. 11

    error: incompatible types: possible lossy conversion from double to int

  12. 12

    Compilation error. lossy conversion from double to int

  13. 13

    (Math.random() * a); possible lossy conversion from double to int

  14. 14

    long to int conversion in java not working

  15. 15

    Inconsistent "possible lossy conversion from int to byte" compile-time error

  16. 16

    Double array method error: Incompatible types: possible lossy conversion from double to int

  17. 17

    Inconsistent "possible lossy conversion from int to byte" compile-time error

  18. 18

    Why I get an error? error: incompatible types: possible lossy conversion from double to int

  19. 19

    Least lossy file conversion for PDF

  20. 20

    Is conversion int -> unsigned long long defined by the standard

  21. 21

    Why doesn't clang warn about implicit conversion from double to int, but do it when from long to int?

  22. 22

    Double to Int without lossy precision

  23. 23

    Why doesn't g++ -Wconversion warn about conversion of double to long int when double is constant?

  24. 24

    Possible lossy from int to char; Occurs when reading in from a text file

  25. 25

    Type conversion: signed int to unsigned long in C

  26. 26

    Why is implicit conversion from int to Long not possible?

  27. 27

    C++ Is conversion from int to long a promotion?

  28. 28

    Java - possible lossy conversion from byte to char

  29. 29

    Problems with using float "possible lossy conversion"

HotTag

Archive