程序员

重新温习 java冒泡排序

2017-02-22  本文已影响63人  sirai
            int minVal = 0;
            int maxVal = 0;
            float min_temperature = 0;
            float max_temperature = 0;
            List<Integer> heartList=new ArrayList<Integer>();
            List<Float> temperList=new ArrayList<Float>();

*list->数组 ->冒泡排序

  Integer[] heart   =heartList.toArray(new Integer[]{heartList.size()});
  Float[] temperature=temperList.toArray(new Float[]{new Float(temperList.size())});


                for (int i=0;i<(heart.length-1);i++){
                    for (int p=0;p<(heart.length-1-i);p++){
                        if (heart[p]>heart[p+1]){
                            int huan=heart[p];
                            heart[p]=heart[p+1];
                            heart[p+1]=huan;
                        }
                    }
                }

                for (int i=0;i<(temperature.length-1);i++){
                    for (int p=0;p<(temperature.length-1-i);p++){
                        if (temperature[p]>temperature[p+1]){
                            float huan=temperature[p];
                            temperature[p]=temperature[p+1];
                            temperature[p+1]=huan;
                        }
                    }
                }

                minVal=heart[0];
                maxVal=heart[heart.length-1];

                min_temperature=temperature[0];
                max_temperature=temperature[temperature.length-1];
 if((Integer.parseInt(entity.getHeartBeat())>0&&Integer.parseInt(entity.getHeartBeat())<minVal)) {
                    minVal = Integer.parseInt(entity.getHeartBeat());
                }

                if((Integer.parseInt(entity.getHeartBeat())>0&&Integer.parseInt(entity.getHeartBeat())>maxVal)){
                    maxVal = Integer.parseInt(entity.getHeartBeat());
                }

                if((Float.parseFloat(entity.getBodyTemp())>0&&Float.parseFloat(entity.getBodyTemp())<min_temperature)){
                    min_temperature = Float.parseFloat(entity.getBodyTemp());
                }

                if((Float.parseFloat(entity.getBodyTemp())>0&&Float.parseFloat(entity.getBodyTemp())>max_temperature)){
                    max_temperature = Float.parseFloat(entity.getBodyTemp());
                }
上一篇下一篇

猜你喜欢

热点阅读