jeudi 10 mai 2018

How to call an algorithm with various array sizes

I am struggling with creating a method where I can create random arrays of various sizes.

I need this because I have to test some algorithms with random arrays, and we need to report on how they do on different input sizes.

To have the different sizes, I though I could create an array of all the input sizes I wanted and loop through it an assign the values to n below but it doesn't seem to be working.

The below code compiles, but I'm not getting the different input sizes. I do however get a random array.

I have the algorithms in question in another class and they're all running fine so I won't include that here - it's just this part which is tripping me up.

Anyone have any ideas?

 public class Array {

        static int[] randomArray(int n){
            int [] inputSize = {50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000};
            for (int i=0; i<inputSize.length; i++){
                n = inputSize[i];
            }
        int[] array = new int[n];
            for (int j = 0; j < n; j++){
             array [j] = (int) (Math.random() * 100); 
        }

        return array;
        }  
    }




Aucun commentaire:

Enregistrer un commentaire