while (result == null&&index<data.length){
    if (data[index].compareTo(target)==0)
    result=data[index];
    index++;
}    Comparable result = null;
    int first = 0 ,last = data.length-1
while( result ==null && first <=last){
    mid =(first + last)/2;
    if(data[mid].compareTo(target)==0)
    result=data[mid];
    else
    if(data[mid].compareTo(target)>0)
    last = mid-1;
    else
    first = mid+1;
}void SelectSort(int a[],int n) //选择排序
{
    int mix,temp;
    for(int i=0;i<n-1;i++) //每次循环数组,找出最小的元素,放在前面,前面的即为排序好的
    {
        mix=i; //假设最小元素的下标
        for(int j=i+1;j<n;j++) //将上面假设的最小元素与数组比较,交换出最小的元素的下标
            if(a[j]<a[mix])
                mix=j;
        //若数组中真的有比假设的元素还小,就交换
        if(i!=mix)
        {
            temp=a[i];
            a[i]=a[mix];
            a[mix]=temp;
        }
    }
}public Integer[] sort(Integer[] a) {
        // TODO Auto-generated method stub
        print("init",a);
        Integer temp = 0;
        for(int i=1;i<a.length;i++) {
            //只能从当前索引往前循环,因为索引前的数组皆为有序的,索引只要确定当前索引的数据的为止即可
            for(int j=i;j>0 && a[j] < a[j-1];j--) {
                temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
            print(i +"",a);
        }
        print("result",a);
        return a;
    }public void bubbleSort(Integer[] arr, int n) {
        if (n <= 1) return; //如果只有一个元素就不用排序了
        for (int i = 0; i < n; ++i) {
            // 提前退出冒泡循环的标志位,即一次比较中没有交换任何元素,这个数组就已经是有序的了
            boolean flag = false;
            for (int j = 0; j < n - i - 1; ++j) {        //此处你可能会疑问的j<n-i-1,因为冒泡是把每轮循环中较大的数飘到后面,
                // 数组下标又是从0开始的,i下标后面已经排序的个数就得多减1,总结就是i增多少,j的循环位置减多少
                if (arr[j] > arr[j + 1]) {        //即这两个相邻的数是逆序的,交换
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag = true;
                }
            }
            if (!flag) break;//没有数据交换,数组已经有序,退出排序
        }
   public static void quickSort(int[] arr,int low,int high){
        int i,j,temp,t;
        if(low>high){
            return;        }
        i=low;
        j=high;
        //temp就是基准位
        temp = arr[low];
        while (i<j) {
            //先看右边,依次往左递减
            while (temp<=arr[j]&&i<j) {
                j--;
            }
            //再看左边,依次往右递增
            while (temp>=arr[i]&&i<j) {
                i++;
            }
            //如果满足条件则交换
            if (i<j) {
                t = arr[j];
                arr[j] = arr[i];
                arr[i] = t;            }
        }
        //最后将基准为与i和j相等位置的数字交换
         arr[low] = arr[i];
         arr[i] = temp;
        //递归调用左半数组
        quickSort(arr, low, j-1);
        //递归调用右半数组
        quickSort(arr, j+1, high);
    }public static int[] sort(int[] a,int low,int high){
        int mid = (low+high)/2;
        if(low<high){
            sort(a,low,mid);
            sort(a,mid+1,high);
            //左右归并
            merge(a,low,mid,high);
        }
        return a;
    }
     
    public static void merge(int[] a, int low, int mid, int high) {
        int[] temp = new int[high-low+1];
        int i= low;
        int j = mid+1;
        int k=0;
        // 把较小的数先移到新数组中
        while(i<=mid && j<=high){
            if(a[i]<a[j]){
                temp[k++] = a[i++];
            }else{
                temp[k++] = a[j++];
            }
        }
        // 把左边剩余的数移入数组 
        while(i<=mid){
            temp[k++] = a[i++];
        }
        // 把右边边剩余的数移入数组
        while(j<=high){
            temp[k++] = a[j++];
        }
        // 把新数组中的数覆盖nums数组
        for(int x=0;x<temp.length;x++){
            a[x+low] = temp[x];
        }
    }






//二分查找,递归实现 recursion
    public static int binarySearch_r(int[] a,int low,int high,int key) {
            int mid = (low+high)/2;
            if(low>=high)
                return -1;
            if(a[mid]==key)
                return mid;
            if(a[mid]>key)
                return binarySearch_r(a,low,mid-1,key);
            return binarySearch_r(a,mid+1,high,key);
    }总结删除结点的思路        delete方法
1、如果该结点同时存在左右子结点
        获取后继结点;
        转移后继结点值到当前结点node;
        把要删除的当前结点设置为后继结点successor。
2、经过步骤1的处理,下面两种情况,只能是一个结点或者没有结点。
    不管有没有结点,都获取子结点child
    if child!=null,就说明有一个结点的情况,此时将父结点与子结点关联上
    if 当前结点没有父结点(后继情况到这一定有父结点),说明要删除的就是根结点,
        根结点设置为child
    else if 当前结点是父结点的左结点
        则将父结点的左结点设置为child
    else 当前结点是父结点的右结点
        则将父结点的右结点设置为child
3、返回被删除的结点node
(statistics.sh脚本的运行结果截图)

最近无检测,故无错题


- 结对学习内容
    - 学习查找
    - 学习排序太忙了,在夹缝中生存,忙里打代码,下周加油!
| 代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
|---|---|---|---|---|
| 目标 | 5000行 | 30篇 | 400小时 | |
| 第一周 | 69/69 | 2/2 | 30/30 | Scanner | 
| 第二、三周 | 529/598 | 3/5 | 25/55 | 部分常用类 | 
| 第四周 | 300/1300 | 2/7 | 25/80 | junit测试和编写类 | 
| 第五周 | 2665/3563 | 2/9 | 30/110 | 接口与远程 | 
| 第六周 | 1108/4671 | 1/10 | 25/135 | 多态与异常 | 
| 第七周 | 1946/6617 | 3/13 | 25/160 | 栈、队列 | 
| 第八周 | 831/7448 | 1/14 | 25/185 | 查找、排序 | 
尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进自己的计划能力。这个工作学习中很重要,也很有用。
耗时估计的公式:Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。
计划学习时间:30小时
实际学习时间:25小时
改进情况:
这周的别的事情较多,所以很急,以后一定好好把本次课程复习一下。
20182301 2019-2020-1 《数据结构与面向对象程序设计》第8周学习总结
原文:https://www.cnblogs.com/zhaopeining/p/11794525.html