1.快速排序:利用分治递归思想
时间复杂度:O(nlogn)最坏的O(N的平方)
空间复杂度:O(logn)最坏的O(n)
特点:不稳定性
选枢纽:三者取中法。位置放在最后能提高速率、
2.单例模式;
①.私有的静态的实例对象 private static instance
②.私有的构造函数(保证在该类外部,无法通过new的方式来创建对象实例) private Singleton(){}
③.公有的、静态的、访问该实例对象的方法 public static Singleton getInstance(){}`
package singleton;
/** * 懒汉式单例类 */
public class LazySingleton {
//私有化构造函数,防止在该类外部通过new的形式创建实例
private LazySingleton() {
System.out.println("生成LazySingleton实例一次!");
}
private static LazySingleton lazyInstance = null;
//公有的访问单例实例的方法,当外部调用访问该实例的方法时,实例才被创建
public static LazySingleton getLazyInstance() {
if (lazyInstance == null) {
lazyInstance = new LazySingleton();
}
return lazyInstance;
}
/饿汉式*/
package singleton;
public class NoLazySingleton {
//私有化构造函数,防止在该类外部通过new的形式创建实例
private NoLazySingleton(){
System.out.println("创建NoLazySingleton实例一次!");
}
private static NoLazySingleton instance = new NoLazySingleton();
//公有的访问单例实例的方法
public static NoLazySingleton getInstance(){
return instance;
}
/线程安全的/
package singleton;
public class SafeLazySingleton {
private SafeLazySingleton(){
System.out.println("生成SafeLazySingleton实例一次!");
}
private static SafeLazySingleton instance = null;
//1.对整个访问实例的方法进行同步
public **synchronized** static SafeLazySingleton getInstance(){
if (instance == null) {
instance = new SafeLazySingleton();
}
return instance;
}
//2.对必要的代码块进行同步
public static SafeLazySingleton getInstance1(){
if (instance == null) {
**synchronized** (SafeLazySingleton.class){
if (instance == null) {
instance = new SafeLazySingleton();
}
}
}
return instance;
}
}
/静态内部/
package singleton;
public class GracefulSingleton {
private GracefulSingleton(){
System.out.println("创建GracefulSingleton实例一次!");
}
//类级的内部类,也就是静态的成员式内部类,该内部类的实例与外部类的实例没有绑定关系,而且只有被调用到才会装载,从而实现了延迟加载
private static class SingletonHoder{
//静态初始化器,由JVM来保证线程安全
private static GracefulSingleton instance = new GracefulSingleton();
}
public static GracefulSingleton getInstance(){
return SingletonHoder.instance;
}
}
3.怎么读取数据库中的信息?
4.项目中最拿手的部分讲一下?
5.springboot 注解
6.springMVC