Java sorting numbers using algorithm -


i have task sort ints in ascending order. task designed practice algorithms... used basic array sort method this:

bufferedreader reader  = new bufferedreader(new inputstreamreader(system.in));      int = integer.parseint((reader.readline()));     int b = integer.parseint((reader.readline()));     int c = integer.parseint((reader.readline()));     int d = integer.parseint((reader.readline()));     int e = integer.parseint((reader.readline()));      int[] ints = {a, b, c, d, e};     arrays.sort(ints);      for(int = 0; i<5;i++)     {         system.out.println(ints[i]);     } 

its not algorithm sure. how without sort method?

you use selection sort:

public static void selectionsort ( int [ ] num ){     int i, j, first, temp;       ( = num.length - 1; > 0; -- ){         first = 0;         for(j = 1; j <= i; j ++) {             if( num[ j ] < num[ first ] )                          first = j;         }         temp = num[ first ];          num[ first ] = num[ ];         num[ ] = temp;      }            } 

you can find list of java sorting algorithms , explanations here


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -