title: algorithm problems (bubble insertion & selection sort) Print out
body: <p>I am running into problems when it comes to the printing. when I run the program I get this:</p>
  <pre><code>TEST PROBLEM: 10 
  0
  0
  0
  0
  0
  0
  0
  0
  10
  </code></pre>
  <p>I am only using the readNumbers() method at the moment (I have commented out the others). I keep running in to a problem where it makes comparisons and swaps. However, printing it out the numbers once there sorted comes out as the following on top.</p>
  <pre><code>File 1 contains: 10,1,2,3,4,5,6,7,8,9,10
  file 2 contains: 10,10,9,8,7,6,5,4,3,2,1
  file 3 contains: 10,3,9,10,8,2,7,5,1,4
  </code></pre>
  <p>My code:</p>
  <pre><code>import java.io.*;
  
  
     public class BubblesortA
      {
       public static void insertionSort (int [] data)
     {
    int comp=0;
    int swaps=0;
  
    int in, out, temp;
  
    for (out=1; out &lt; data.length; out++)
    {
       temp = data[out];
       comp++;
  
       for (in=out; in &gt; 0 &amp;&amp; data[in-1] &gt;= temp; in--)
       {
          data[in] = data[in-1];
          swaps++;
       }
       data[in] = temp;
    }
  
    System.out.println(&quot;Insertions sort comps: &quot;+comp);
    System.out.println(&quot;Insertion sort swap: &quot;+swaps);
    System.out.println();
  
  }
  
  
     public static void selectSort (int [] data )
     {
    int in, out, min;
    int counter;
    int comparisons=0;
    int swaps=0;
  
    for (out=0; out &lt; data.length-1; out++)
    {
       min = out;
       comparisons++;
  
       for (in = out+1; in &lt; data.length; in++)
       {
          if (data[in] &lt; data[min])
          {
             min = in; // new minimum
  
             swaps++;
          }
       }
  
       int tmp = data[out];     // swap items
       data[out] = data[min];   //
       data[min] = tmp;          //
      }
  
      System.out.println(&quot;Select sort Comp: &quot;+comparisons);
      System.out.println(&quot;Select sort Swaps: &quot;+swaps);
      System.out.println();
  
  
  
  
  
    }
  
    public static void generateRandom(int gty)
    {
       int counter;
       int [] fillArray = new int [gty];
       int random;
  
  
     for (counter=0; counter &lt; fillArray.length; counter++)
    {
       random = (int) (Math.random() * 100+1);
       fillArray [counter]  = random;
  
  
    }
  
    bubbleSort(fillArray);
    selectSort(fillArray);
    insertionSort(fillArray);
  }
     public static void readNumbers (String fileName)
   {
    int counter;
    int number;
    int  [] data = new int[fileName.length()];
  
  
    try
    {
       FileReader fr = new FileReader(fileName);
       BufferedReader br = new BufferedReader(fr);
       fileName = br.readLine();
  
       for(counter=0; counter &lt; fileName.length(); counter++)
       {
          number = Integer.parseInt(fileName);
          data [counter] = number;
  
          System.out.println(&quot; TEST PROBLEM: &quot;+number+ &quot; &quot;);
  
          fileName = br.readLine();
       }
       br.close();
       fr.close();
  
  
  
       bubbleSort(data);
  
  
  
    }
    catch (IOException e)
    {
       System.out.println(e);
    }
  
  
   }
    public static void bubbleSort (int [] numbers)
   {
     int outter;
     int inner;
     int temp;
     int counter;
     boolean sorted = false;
  
     int comparisons=0;
     int swaps =0;
  
  
     while(!sorted)
     {
     for(outter=0; outter &lt; numbers.length; outter++)
     {
       comparisons++;
       sorted = true;
  
       for (inner = 0; inner &lt; numbers.length - 1 - outter; inner++)
       {
          if (numbers[inner] &gt; numbers[inner + 1])
          {
             temp = numbers[inner];
             numbers[inner] = numbers[inner + 1];
             numbers[inner + 1] = temp;
  
             swaps++;
             sorted = false;
            }
  
         }
      }
    /**
       int hold = numbers.length -1;
  
       while (hold != 0 &amp;&amp; sorted)
       {
          comparisons++;
          sorted = false;
          for (inner = 0; inner &lt; hold; inner++)
          {
             if (numbers[inner] &gt; numbers[inner + 1])
             {
                temp = numbers[inner];
                numbers[inner] = numbers[inner + 1];
                numbers[inner + 1] = temp;
  
                swaps++;
                sorted = true;
             }
  
          }
  
  
       }
     */
  
  
    }
  
    for(counter=0; counter &lt; numbers.length; counter++)
    {
       System.out.println(numbers[counter]);
    }
  
    System.out.println();
    System.out.println(&quot;BubbleSort Comparsions: &quot;+comparisons);
    System.out.println(&quot;BubbleSort Swaps: &quot;+swaps);
    System.out.println();
  
   }
  </code></pre>
  <p>public static void main(String[] args)
  {</p>
  <pre><code>  int [] = {10,9,8,7,6,5,4,3,2,1,};
   
    String file1 = &quot;File1.txt&quot;;
    String file2 = &quot;File2.txt&quot;;
    String file3 = &quot;File3.txt&quot;;
  
  
    //bubbleSort(data);
  
     readNumbers(&quot;File1.txt&quot;);
    //readNumbers(&quot;File2.txt&quot;);
    //readNumbers(&quot;File3.txt&quot;);
    //generateRandom(100);
  
     }//main
   }//class 
  </code></pre>