-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.java
More file actions
31 lines (29 loc) · 1.15 KB
/
Task3.java
File metadata and controls
31 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package Work01.Unit01;
public class Task3 {
/**
* Задание 3
* Дан массив nums = [3,2,2,3] и число val = 3.
* Если в массиве есть числа, равные заданному, нужно перенести эти элементы в конец массива.
* Таким образом, первые несколько (или все) элементов массива должны быть отличны от заданного,
* а остальные - равны ему.
*/
public static int[] TransferringArrayElements(int[] TempArr, int Input) {
int Left = 0, Right = TempArr.length - 1, Temp;
while (Left < Right) {
if (TempArr[Left] != Input) {
Left++;
}
if (TempArr[Right] == Input) {
Right--;
}
if (TempArr[Left] == Input && TempArr[Right] != Input) {
Temp = TempArr[Right];
TempArr[Right] = TempArr[Left];
TempArr[Left] = Temp;
Left++;
Right--;
}
}
return TempArr;
}
}