一般认为快速排序的最佳情况是O(nlogn),因为阵列每次分区大约一半.还有人说最坏的情况是n ^ 2阶,假设数组已经排序.
我们不能通过设置一个名为swap的布尔值来修改quicksort吗?例如,如果第一遍的位置没有初始交换,那么我们可以假设数组已经排序,因此不再对数据进行分区.
我知道修改后的冒泡排序通过检查交换来使用它,允许最好的情况是O(n)而不是O(n ^ 2).这种方法可以应用于快速排序吗?为什么或者为什么不?
我听说苹果改变了一些东西,关于iOS 5中的内存管理.那么最好的位置是什么,在我的新iOS 5应用程序中保存应用程序数据和文件 - 而不会丢失数据?
我试图优化我的一些PHP代码.我发现我的PHP脚本的大部分时间是在脚本开头的mysql数据库连接期间花费的.
我只在开始时连接到数据库一次,并在脚本结束时关闭数据库连接.
但是对于请求此页面的每个用户,必须建立新的连接.
有没有办法保存对数据库的引用并为所有请求共享它?
我想在动画结束后执行doSomethingElse.另一个限制是动画代码可以具有不同的持续时间.我怎样才能做到这一点?谢谢!
-(void) doAnimationThenSomethingElse {
[self doAnimation];
[self doSomethingElse];
}
Run Code Online (Sandbox Code Playgroud)
例如,这不起作用:
animationDuration = 1;
[UIView animateWithDuration:animationDuration
animations:^{
[self doAnimation];
} completion:^(BOOL finished) {
[self doSomethingElse];
}
];
Run Code Online (Sandbox Code Playgroud) 在我的一个视图控制器代码中,我有这一行:
[NSTimer scheduledTimerWithTimeInterval:7.0 target:self selector:@selector(doSomethingOnce) userInfo:nil repeats:NO];
Run Code Online (Sandbox Code Playgroud)
它在7秒后被调用并执行某些操作...(我没有将计时器分配给变量或属性)
如果在7秒钟结束之前释放视图控制器,会发生什么情况?
我是否必须在某个时候释放计时器和/或使计时器无效(即在dealloc中)?
如何检查UITableViewCell是否在屏幕上完全可见(不是通过选项卡或导航栏切断)?
我可以使用以下代码获取可见单元格:
NSArray *indexes = [_tableView indexPathsForVisibleRows];
Run Code Online (Sandbox Code Playgroud)
但我想排除屏幕中不完全可见的单元格.
我想将InputFilter应用于我的EditTextPreferences ...
在我使用PreferenceActivity之前,我使用了EditTexts和Filters之类的:
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.ETminsim);
et3 = (EditText) findViewById(R.id.ETdelay);
et1.setText(Integer.toString(PlotView.playlist_size), EditText.BufferType.EDITABLE);
et2.setText(Integer.toString(conversorToInt(PlotView.min_sim)), EditText.BufferType.EDITABLE);
et3.setText(Integer.toString(MusicService.getSeek()/1000), EditText.BufferType.EDITABLE);
et1.setFilters(new InputFilter[]{ new InputFilterMinMax(1, 30)});
et2.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
et3.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 300)});
Run Code Online (Sandbox Code Playgroud)
但是如何引用EditTextPreference的EditTexts来设置这些过滤器?
我的新代码:
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
getPreferenceManager().setSharedPreferencesName(Singleton.PREFS_NAME);
addPreferencesFromResource(R.xml.prefs);
//TODO set InputFilter
}
Run Code Online (Sandbox Code Playgroud)