Commit ead6ae8
committed
feat: Implement element insertion at a specific index in an array with manual shifting [array-insertion-basic]
📌 Core Concept:
Demonstrates how to insert a new element into an existing array by shifting elements manually to make space at a given index.
🧮 Program Overview:
- Initializes an integer array `A` with a fixed capacity.
- Populates the first 6 elements manually.
- Prints the original array state.
- Inserts element `20` at index `2` by:
- Shifting elements one position to the right starting from the end.
- Placing the new value at the specified index.
- Prints the updated array.
🧪 Behavior:
- Original: `3, 9, 7, 8, 12, 6`
- After insertion at index 2: `3, 9, 20, 7, 8, 12`
📌 Key Features:
- Demonstrates low-level control over array manipulation.
- Highlights index-based shifting to manage fixed-size arrays.
✅ Useful for:
- Understanding static array limitations in Java.
- Teaching manual memory shifting before using higher-level structures (like `ArrayList`).
Signed-off-by: Somesh diwan <[email protected]>1 parent 26710e3 commit ead6ae8
1 file changed
+2
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
0 commit comments