java - adding elements to an array and call sort method -


i having difficulty trying load 50 elements file array , call bubble sort. can tell me doing wrong. have loading entire list array. need pick out 50 first or random element , call bubblesort method.

public class sorts {     public static int bubblecount = 0;      public static void bubblesort(double data[], int count)     {         int pass, i;          double temp;         boolean done;         done = false;         (pass = 0; !done; pass++)         {              done = true;             (i = 0; < count - 1 - pass; i++)             {                 bubblecount++;                 if (data[i] > data[i+1])                 {                     temp = data[i];                     data[i] = data[i+1];                     data[i+1] = temp;                     done = false;                 }             }         }     } } 

here main class

public class mainsort {     static file numdata;     static scanner s;     public static void main(string[] args) throws filenotfoundexception      {         numdata = new file("num.dat");            try          {             s = new scanner(numdata);         } catch (filenotfoundexception e) {         }         double[] array = new double[1];         while(s.hasnext())         {             int i=0;             array[i]=s.nextdouble();             //print             //system.out.println(array[i]);             i++;         }         sorts sorted = new sorts();         sorted.bubblesort(array[50]);      } } 

declare variable int i outside loop:

      int i=0;       while(s.hasnext()){             array[i]=s.nextdouble();             //print             //system.out.println(array[i]);             i++;             } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -