Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8a53ea16cd693a88382846e1ac02fd716bdafe62
Choose a base ref
..
head repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c4eead424ab042441a662a62b91f516aa0da1a10
Choose a head ref
4 changes: 1 addition & 3 deletions src/algorithms/sorting/bubble-sort/BubbleSort.js
Original file line number Diff line number Diff line change
@@ -19,9 +19,7 @@ export default class BubbleSort extends Sort {

// Swap elements if they are in wrong order.
if (this.comparator.lessThan(array[j + 1], array[j])) {
const tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
[array[j], array[j + 1]] = [array[j + 1], array[j]];

// Register the swap.
swapped = true;
Original file line number Diff line number Diff line change
@@ -27,14 +27,10 @@ describe('CountingSort', () => {
const sorter = new CountingSort({ visitingCallback });

// Detect biggest number in array in prior.
const biggestElement = notSortedArr.reduce((accumulator, element) => {
return element > accumulator ? element : accumulator;
}, 0);
const biggestElement = Math.max(...notSortedArr);

// Detect smallest number in array in prior.
const smallestElement = notSortedArr.reduce((accumulator, element) => {
return element < accumulator ? element : accumulator;
}, 0);
const smallestElement = Math.min(...notSortedArr);

const sortedArray = sorter.sort(notSortedArr, smallestElement, biggestElement);

27 changes: 20 additions & 7 deletions src/data-structures/linked-list/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,20 @@ Add(value)
end if
end Add
```


```
Prepend(value)
Pre: value is the value to add to the list
Post: value has been placed at the head of the list
n ← node(value)
n.next ← head
head ← n
if tail = ø
tail ← n
end
end Prepend
```

### 搜索

```text
@@ -67,10 +80,10 @@ Remove(head, value)
end if
return true
end if
while n.next = ø and n.next.value = value
while n.next != ø and n.next.value != value
n ← n.next
end while
if n.next = ø
if n.next != ø
if n.next = tail
tail ← n
end if
@@ -88,7 +101,7 @@ Traverse(head)
Pre: head is the head node in the list
Post: the items in the list have been traversed
n ← head
while n = 0
while n != 0
yield n.value
n ← n.next
end while
@@ -101,11 +114,11 @@ end Traverse
ReverseTraversal(head, tail)
Pre: head and tail belong to the same list
Post: the items in the list have been traversed in reverse order
if tail = ø
if tail != ø
curr ← tail
while curr = head
while curr != head
prev ← head
while prev.next = curr
while prev.next != curr
prev ← prev.next
end while
yield curr.value
2 changes: 1 addition & 1 deletion src/data-structures/tree/fenwick-tree/FenwickTree.js
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ export default class FenwickTree {
*/
queryRange(leftIndex, rightIndex) {
if (leftIndex > rightIndex) {
throw new Error('Left index can not be greater then right one');
throw new Error('Left index can not be greater than right one');
}

if (leftIndex === 1) {