Last active
November 23, 2025 08:25
-
-
Save timxor/053e04a5e0a7130d42c286e6d3555e31 to your computer and use it in GitHub Desktop.
Processes left-to-right and works safely only when ranges don't overlap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Forward Copy (left-to-right) | |
| // Suitable when source and destination ranges do NOT overlap, | |
| // or when destination is entirely to the left of source | |
| public static void forwardCopy(int[] arr, int srcStart, int destStart, int length) { | |
| for (int i = 0; i < length; i++) { | |
| arr[destStart + i] = arr[srcStart + i]; | |
| } | |
| } | |
| // Example: Copy elements without overlap | |
| // Original: [1, 2, 3, 4, 5] | |
| // Copy indices 1-3 to indices 3-5 | |
| // Result: [1, 2, 3, 2, 3, 4] (indices 3-5 now contain [2, 3, 4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment