You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -63,7 +63,7 @@ What remains is the `insert()` function. Here is an initial stab at it:
63
63
}
64
64
```
65
65
66
-
The helper function `findInsertionPoint()` simply iterates through the entire array, looking for the right place to insert the new element.
66
+
The helper function `findInsertionPoint()` simply iterates through the entire array, looking for the right place to insert the new element.
67
67
68
68
> **Note:** Quite conveniently, `array.insert(... atIndex: array.count)` adds the new object to the end of the array, so if no suitable insertion point was found we can simply return `array.count` as the index.
69
69
@@ -81,26 +81,28 @@ a.insert(10) // inserted at index 8
81
81
a // [-2, -1, 1, 3, 4, 5, 7, 9, 10]
82
82
```
83
83
84
-
The array's contents will always be sorted from low to high, now matter what.
84
+
The array's contents will always be sorted from low to high, now matter what.
85
85
86
86
Unfortunately, the current `findInsertionPoint()` function is a bit slow. In the worst case, it needs to scan through the entire array. We can speed this up by using a [binary search](../Binary Search) to find the insertion point.
0 commit comments