java - Finding min and max point in a series -


i got series this:

20 22 25 27 30 31 30 25 22 19 21  25 28 30 28 27... 

as numbers reach near 30, start moving negatively, , reach near 20, start moving positively.

i need find these 2 points using sort of algo. i'm totally lost.

i can't sort because 31 max , 19 min.

in real implementation, numbers can change, , can float well, instead of int. can this:

55.20 57.35 54.30 59.25 61.00 58.20 55.40 53.50 58.75 60.10 55.15 53.40 50.00 51.10 52.00 

in case 53 , 60 points, , additionally, third lower point 50.00.

how go ahead on this?

import java.util.list; import java.util.arraylist;  public class getextrema  {    public static <t extends comparable<t>> list<t> getextrema(t[] series) {     list<t> extrema = new arraylist<t>();     extrema.add(series[0]);     boolean upelsedown = series[1].compareto(series[0]) > 0;     (int = 2; < series.length; ++i) {         if (series[i].compareto(series[i-1]) > 0 != upelsedown) {             extrema.add(series[i-1]);             upelsedown = !upelsedown;         } // end if     } // end     extrema.add(series[series.length-1]);     return extrema;   } // end getextrema()    public static void main(string[] args) {      integer[] s1 = {20,22,25,27,30,31,30,25,22,19,21,25,28,30,28,27};     list<integer> extrema = getextrema(s1);     system.out.println(extrema);      double[] s2 = {55.2,57.3,54.3,59.2,61.,58.2,55.4,53.5,58.7,60.1,55.1,53.4,50.,51.1,52.};     list<double> extrema2 = getextrema(s2);     system.out.println(extrema2);      system.exit(0);    } // end main()  } // end class getextrema 

compilation , execution:

javac getextrema.java; classpath=. java getextrema; ## [20, 31, 19, 30, 27] ## [55.2, 57.35, 54.3, 61.0, 53.5, 60.1, 50.0, 52.0] 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -