IOS 中给数据排序的两种方法---持续更新中---
来源:互联网 发布:录屏软件哪款好 编辑:程序博客网 时间:2024/06/06 12:23
// 方法一 比 方法二 快 10倍以上,分别为大概0.000010 、0.000110左右
// 但是 方法二 更节省代码, 所以我还是采用方法 二
// float themaxBloodSugar; // 最大值// float theminBloodSugar; // 最小值 float thesumBloodSugar; // 平均值// float themaxWeight; // 最大值 weight// float theminWeight; // 最小值 weight float thesunWeight; // 平均值 weight tb_History *maxHistory = (tb_History *)[historys objectAtIndex:0]; tb_History *minHistory = (tb_History *)[historys objectAtIndex:0]; tb_History *maxWeightHistory = (tb_History *)[historys objectAtIndex:0]; tb_History *minWeightHistory = (tb_History *)[historys objectAtIndex:0]; tb_History *lastHistory = (tb_History *)[historys objectAtIndex:0]; // tb_History *tmpHistory = (tb_History *)[historys objectAtIndex:0];// themaxBloodSugar = [tmpHistory.BloodSugar floatValue];// theminBloodSugar = [tmpHistory.BloodSugar floatValue];// thesumBloodSugar = [tmpHistory.BloodSugar floatValue];// themaxWeight = [tmpHistory.Weight floatValue];// theminWeight = [tmpHistory.Weight floatValue];// thesunWeight = [tmpHistory.Weight floatValue];// // //方法一:// // NSDate *date1 = [NSDate date];// // //最大值、最小值、平均值// //weight 最大值、最小值、平均值// for (int i = 1; i < recycleCount; ++i) {// tb_History *thetmpHistory = (tb_History *)[historys objectAtIndex:i];// // //bloodSugar// if (thetmpHistory.BloodSugar.floatValue - themaxBloodSugar > 0.000001)// {// maxHistory = thetmpHistory;// themaxBloodSugar = thetmpHistory.BloodSugar.floatValue;// }// if (theminBloodSugar - thetmpHistory.BloodSugar.floatValue >0.000001) {// minHistory = thetmpHistory;// theminBloodSugar = thetmpHistory.BloodSugar.floatValue;// }// thesumBloodSugar += thetmpHistory.BloodSugar.floatValue;// // //weight// if (thetmpHistory.Weight.floatValue - themaxWeight > 0.000001)// {// maxWeightHistory = thetmpHistory;// themaxWeight = thetmpHistory.Weight.floatValue;// }// if (theminWeight - thetmpHistory.Weight.floatValue >0.000001) {// minWeightHistory = thetmpHistory;// theminWeight = thetmpHistory.Weight.floatValue;// }// thesunWeight += thetmpHistory.Weight.floatValue;// }// // NSDate *date2 = [NSDate date];// NSLog(@"%f",[date2 timeIntervalSinceDate:date1]); // 方法二: NSDate *date1 = [NSDate date]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"BloodSugar" ascending:NO]; [historys sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; maxHistory = [historys objectAtIndex:0]; minHistory = [historys objectAtIndex:historys.count - 1]; for (tb_History *oneHistory in historys) { thesumBloodSugar += oneHistory.BloodSugar.floatValue; thesunWeight += oneHistory.Weight.floatValue; } [sortDescriptor release]; NSSortDescriptor *sortWeightDescriptor = [[NSSortDescriptor alloc]initWithKey:@"Weight" ascending:NO]; [historys sortUsingDescriptors:[NSArray arrayWithObject:sortWeightDescriptor]]; maxWeightHistory = [historys objectAtIndex:0]; minWeightHistory = [historys objectAtIndex:historys.count - 1]; [sortWeightDescriptor release]; NSDate *date2 = [NSDate date]; NSLog(@"%f",[date2 timeIntervalSinceDate:date1]);
- IOS 中给数据排序的两种方法---持续更新中---
- Java实现数据排序(冒泡、选择、插入、快速排序)---方法持续更新中
- iOS开发中总结的小技巧(持续更新中)
- iOS开发——来改掉那些已经过时的方法吧(持续更新中)
- java中关于给属性赋值的两种方法
- Word中样式更新的两种方法!
- iOS中涉及到的几种通信方式-持续更新中~~~~
- iOS 版本更新的两种方法
- ios 常用的开源代码(持续更新中)
- iOS开发中一些有用的小代码(持续更新)
- 一些比较好的iOS开发博客持续更新中
- 经典排序算法综述 持续更新中
- 排序小结(持续更新中。。。)
- Javascript排序算法(持续更新中...)
- 排序算法总结(持续更新中)
- iOS开发常用代码【持续更新中】
- iOS错误总结。。。。。持续更新中
- iOS常见问题总结....持续更新中
- image segmentation emulating ecognition source code in vc6 下载地址
- 宋涛曝86世锦赛故意输球 为淘汰德国投自家篮筐
- 虚拟机不能“上网”或不能“桥接”的解决方案
- 10.多个Job,多个quartz_jobs.xml文件:quartz_jobs.xml,quartz_job2.xml
- www.unix-center.net真的很好
- IOS 中给数据排序的两种方法---持续更新中---
- 11.多个Job,多个quartz_jobs.xml文件:quartz.properties
- Windows Shell编程-第二章.Shell的结构
- hdu 确定比赛名次(拓扑排序)
- C#常见错误及解决方案
- Eclipse配置SVN
- Oracle Form 如何制作手电筒查询
- Android 4.0 Launcher2源码分析——主布局文件
- Merging PDF Files in Cocoa