|
|
|
|
1
|
|
1
|
|
2
|
# Delete Duplicates
|
2
|
# Delete Duplicates
|
3
|
* **Objective**
|
3
|
* **Objective**
|
4
|
- * To write methods which removes duplicate elements from an array.
|
|
|
|
|
4
|
+ * To write methods which remove duplicate elements from an array.
|
5
|
* **Purpose**
|
5
|
* **Purpose**
|
6
|
* To demonstrate practical understanding of `while`, `for`, and `for each` loops.
|
6
|
* To demonstrate practical understanding of `while`, `for`, and `for each` loops.
|
7
|
* **Instructions**
|
7
|
* **Instructions**
|
|
|
|
|
39
|
```
|
39
|
```
|
40
|
// : Given
|
40
|
// : Given
|
41
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
41
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
42
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
42
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
43
|
|
43
|
|
44
|
// : When
|
44
|
// : When
|
45
|
Integer[] actual = deleter.removeDuplicateExactly(3);
|
45
|
Integer[] actual = deleter.removeDuplicateExactly(3);
|
|
|
|
|
63
|
```
|
63
|
```
|
64
|
// : Given
|
64
|
// : Given
|
65
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
65
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
66
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
66
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
67
|
|
67
|
|
68
|
// : When
|
68
|
// : When
|
69
|
Integer[] actual = deleter.removeDuplicateExactly(1);
|
69
|
Integer[] actual = deleter.removeDuplicateExactly(1);
|
|
|
|
|
87
|
```
|
87
|
```
|
88
|
// : Given
|
88
|
// : Given
|
89
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
89
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
90
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
90
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
91
|
|
91
|
|
92
|
// : When
|
92
|
// : When
|
93
|
Integer[] actual = deleter.removeDuplicateExactly(3);
|
93
|
Integer[] actual = deleter.removeDuplicateExactly(3);
|
|
|
|
|
129
|
```
|
129
|
```
|
130
|
// : Given
|
130
|
// : Given
|
131
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
131
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
132
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
132
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
133
|
|
133
|
|
134
|
// : When
|
134
|
// : When
|
135
|
Integer[] actual = deleter.removeDuplicateExactly(1);
|
135
|
Integer[] actual = deleter.removeDuplicateExactly(1);
|
|
|
|
|
155
|
```
|
155
|
```
|
156
|
// : Given
|
156
|
// : Given
|
157
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
157
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
158
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
158
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
159
|
|
159
|
|
160
|
// : When
|
160
|
// : When
|
161
|
Integer[] actual = deleter.removeDuplicates(2);
|
161
|
Integer[] actual = deleter.removeDuplicates(2);
|
|
|
|
|
180
|
```
|
180
|
```
|
181
|
// : Given
|
181
|
// : Given
|
182
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
182
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
183
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
183
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
184
|
|
184
|
|
185
|
// : When
|
185
|
// : When
|
186
|
Integer[] actual = deleter.removeDuplicates(3);
|
186
|
Integer[] actual = deleter.removeDuplicates(3);
|
|
|
|
|
215
|
```
|
215
|
```
|
216
|
// : Given
|
216
|
// : Given
|
217
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
217
|
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
|
218
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
218
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
219
|
deleter.removeDuplicates(0);
|
219
|
deleter.removeDuplicates(0);
|
220
|
deleter.removeDuplicates(1);
|
220
|
deleter.removeDuplicates(1);
|
221
|
deleter.removeDuplicates(2);
|
221
|
deleter.removeDuplicates(2);
|
|
|
|
|
242
|
```
|
242
|
```
|
243
|
// : Given
|
243
|
// : Given
|
244
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
244
|
Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
|
245
|
- DuplicateDeleter deleter = new DuplicateDeleter(array);
|
|
|
|
|
245
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
|
246
|
deleter.removeDuplicates(0);
|
246
|
deleter.removeDuplicates(0);
|
247
|
deleter.removeDuplicates(1);
|
247
|
deleter.removeDuplicates(1);
|
248
|
deleter.removeDuplicates(2);
|
248
|
deleter.removeDuplicates(2);
|