美文网首页程序员
重新温习 java冒泡排序

重新温习 java冒泡排序

作者: sirai | 来源:发表于2017-02-22 12:11 被阅读63次
    • 声明属性
                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];
    
    • list直接循环取出大小值
     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());
                    }
    

    相关文章

      网友评论

        本文标题:重新温习 java冒泡排序

        本文链接:https://www.haomeiwen.com/subject/qezpwttx.html