Delete Element from Array
C++
Medium
6 views
Problem Description
Remove an element at a specific index and shift remaining
elements left. This teaches array manipulation and size management.
Logic: Shift all elements after deletion point one position left
Official Solution
void question7_delete_element() {
int arr[] = {10, 20, 30, 40, 50};
int size = 5;
int deletePos = 2;
for(int i = deletePos; i < size - 1; i++) {
arr[i] = arr[i + 1];
}
size--;
cout << "Array after deletion: ";
for(int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!