diff --git a/src/com/zejian/structures/LinkedList/singleLinked/SingleILinkedList.java b/src/com/zejian/structures/LinkedList/singleLinked/SingleILinkedList.java index f780483..82e0f6f 100644 --- a/src/com/zejian/structures/LinkedList/singleLinked/SingleILinkedList.java +++ b/src/com/zejian/structures/LinkedList/singleLinked/SingleILinkedList.java @@ -218,36 +218,31 @@ public T remove(int index) { @Override public boolean removeAll(T data) { - boolean isRemove=false; + boolean isRemove = false; - if(this.head!=null&&data!=null){ - - //如果移除的是头结点 - if(data.equals(this.head.data)){ - this.head=this.head.next; - isRemove=true; + if(this.head != null && data != null){ + //如果移除的是头节点 + if(data.equals(this.head.data)){ + this.head = this.head.next; + isRemove = true; + } + + Node front = this.head; + Node pre = front.next; + //查找所有数据相同的节点并删除 + while(pre != null){ + if(data.equals(pre.data)){ + front.next = pre.next; + pre = front.next; + isRemove = true; }else { - - Node front=this.head; - Node pre=front.next; - //查找所有数据相同的结点并删除 - while (pre!=null){ - - if(data.equals(pre.data)){ - //更改指针指向 - front.next=pre.next; - pre =front.next; - isRemove=true; - }else { - front=pre; - pre=pre.next; - } - } + front = pre; + pre = pre.next; } - }else {//data=null || this.head=null - isRemove=false; } - return isRemove; + + } + return isRemove; } /** diff --git a/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort.java b/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort.java index c5ef77b..79495ee 100644 --- a/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort.java +++ b/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort.java @@ -19,7 +19,7 @@ * 时间复杂度分析: * 快速排序每次将待排序数组分为两个部分,在理想状况下, * 每一次都将待排序数组划分成等长两个部分,则需要logN次划分 - * 即存在N层,而每层需要处理的元素个数都是一样的即N,此时时间 + * 即存在 logN 层,而每层需要处理的元素个数都是一样的即N,此时时间 * 复杂度为 N*logN * 而在最坏情况下,即数组已经有序或大致有序的情况下,每次划分 * 只能减少一个元素,快速排序将不幸退化为冒泡排序,因为每次分 diff --git a/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort2Ways.java b/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort2Ways.java index 2b82fcb..b58d184 100644 --- a/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort2Ways.java +++ b/src/com/zejian/structures/Sort/Sort_NLogN/QuickSort2Ways.java @@ -43,9 +43,9 @@ private static > void quickSort2Ways(T[] arr , int l , i InsertionSort.sort(arr,l,r); return; } - if( l >= r){ - return; - } +// if( l >= r){ +// return; +// } //计算并获取基准点的下标 int p = partition(arr,l,r);