-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryCopy.java
More file actions
50 lines (35 loc) · 1.16 KB
/
Copy pathMemoryCopy.java
File metadata and controls
50 lines (35 loc) · 1.16 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Algorithms;
import java.util.Scanner;
import static java.lang.System.arraycopy;
public class MemoryCopy {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int v[] = new int[n];
for(int i = 0; i < n; i ++) {
v[i] = in.nextInt();
}
int dest = in.nextInt();
int src = in.nextInt();
int size = in.nextInt();
memcpy(v, dest, src, size);
// memcpy(v, 50, 0, -1); // may throw RuntimeException or do nothing
// memcpy(v, 10, 20, 512);
// memcpy(v, 20, 10, 512);
// memcpy(v, 50, 0, 0); // may throw RuntimeException or do nothing
// memcpy(v, 50, 0, 1);
}
static void memcpy(int[] v, int dest, int src, int size) {
if(size < 1) {
for(int i = 0; i < v.length; i ++ ) {
System.out.print(v[i] + " ");
}
System.out.println();
throw new RuntimeException();
}
arraycopy(v, src, v, dest, size);
for(int i = 0; i < v.length; i ++ ) {
System.out.print(v[i] + " ");
}
}
}