12 Replies Latest reply: Dec 10, 2008 11:01 PM by 843785 RSS

    Selection Sort on Array

    843785
      hey guys

      ive starterd writing the following program and i seam to have gone verry wrong , can anyone point out my main errors ?
      import java.util.*;
       
      public class selection
      {
      
      public static void selectionsort(double[]list{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.0;}) 
      {
      for (int i = list.length - 1; i>= 1; i--)
      {
      double currentMax = list[0];
      int currentMaxIndex = 0;
      
      For (int j = 1; j<=i; j++;)
      {
      if (currentMax < list[j])
      {
      currentMax = list[j];
      currentMaxIndex = j;
      }
      }
      if (currentMaxIndex != i)
      {
      list[currentMaxIndex] = list;
      list [i] = currentMax;
      }
      }
      }
      }
      }


      Edited by: Javaman01 on Dec 10, 2008 3:56 PM < corrected a few errors
      
      Edited by: Javaman01 on Dec 10, 2008 3:57 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        • 1. Re: Selection Sort on Array
          843785
          Javaman01 wrote:
          ive starterd writing the following program and i seam to have gone verry wrong , can anyone point out my main errors ?
          First correct all syntax errors so the program compiles correctly.

          You've written For instead of for at one point for example.
          • 2. Re: Selection Sort on Array
            843785
            http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html#sort(double[])
            • 3. Re: Selection Sort on Array
              843785
              Also give a detailed error, don't just come up saying fix my code, Include whether its compile/run time error and the error description.
              • 4. Re: Selection Sort on Array
                843785
                import java.util.*;
                 
                public class Selectionsort
                {
                 
                public static void selectionsort(new double[]list{1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0});
                {
                for (int i = list.length - 1; i>= 1; i--)
                {
                double currentMax = list[0];
                int currentMaxIndex = 0;
                 
                for (int j = 1; j <=i; j++;)
                {
                if (currentMax < list[j])
                {
                currentMax = list[j];
                currentMaxIndex = j;
                }
                }
                if (currentMaxIndex != i)
                {
                list[currentMaxIndex] = list;
                list [i] = currentMax;
                }
                }
                }
                }
                i have removed some more error's
                
                Errors : http://img354.imageshack.us/img354/755/errordocha1.jpg
                
                There seams to be errors that should not be apearing in the code...
                
                Also how would i print the output from this ?
                
                Edited by: Javaman01 on Dec 10, 2008 4:11 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                • 5. Re: Selection Sort on Array
                  843785
                  Javaman01 wrote:
                  There seams to be errors that should not be apearing in the code...
                  Come on now. Read what the compiler says and fix that.

                  Here for example the rightmost semicolon shouldn't be there.

                  for (int j = 1; j <=i; j++;)
                  • 6. Re: Selection Sort on Array
                    843785
                    i have fixed the error you displayed but the compiler tells me to make line 6 like this ...??? im not that great with error's

                    public static void selectionsort (new) double;] list;1.1; 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0};

                    Edited by: Javaman01 on Dec 10, 2008 4:20 PM
                    • 7. Re: Selection Sort on Array
                      843785
                      Could anyone give me the solution to this problem? i have been trying myself but find it almost impossable to comprehend :(
                      • 8. Re: Selection Sort on Array
                        843785
                        What exactly are you trying to do in this class?
                        • 9. Re: Selection Sort on Array
                          843785
                          Sinanju180 wrote:
                          What exactly are you trying to do in this class?
                          Cheat, it seems.
                          • 10. Re: Selection Sort on Array
                            843785
                            Hey I'd love to help, but I have no idea whats up and whats down.
                            • 11. Re: Selection Sort on Array
                              843785
                              {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.0;}
                              What's the point in sorting a sorted List?
                              • 12. Re: Selection Sort on Array
                                843785
                                Javaman01 wrote:
                                Could anyone give me the solution to this problem? i have been trying myself but find it almost impossable to comprehend :(
                                public void sort(?[] ){
                                
                                // I = iterate over values
                                // J = iterate from ? to the end
                                // check if min
                                // swap
                                
                                }
                                Seriously, its like 6 lines of code. Man up.