面试题集合---数据结构

来源:互联网 发布:linux上jsp页面跳转 编辑:程序博客网 时间:2024/05/28 17:07

1.数据结构

排序算法(时间复杂度和空间复杂度以及具体实现)

1.冒泡排序

时间复杂度o(n*n)

public class Main {
    public static void main(String[] args) {
        int a[] = { 1, 3, 2, 4, 6, 5 };
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] < a[j]) {
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        for (int i = 0;i<a.length;i++) {
            System.out.println(a[i]);
        }
    }
}

冒泡排序非常简单没什么必须讲的

2.快排 0(nlogn)

快排是一种不稳定的排序,一般用来处理数据比较散乱的情况

public Main{

        public static port(){

        }

        public static void sort(){

      

       }

       public static void main(String [] args){

              

        }       

}

3.