Created
March 5, 2015 01:49
-
-
Save frmsaul/91154a63ddf574e0ab06 to your computer and use it in GitHub Desktop.
"C++ code to insert an element into middle of array"
This file contains 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
//insert integer x into index ind | |
void insert_to_arr(int* arr, int arr_size, int x, int ind){ | |
arr = (int*)realloc(arr, sizeof(int) * (arr_size + 1) ); | |
print_array(arr, arr_size + 1); | |
for(int i = arr_size; i > ind; i--){ | |
arr[i] = arr[i - 1]; | |
} | |
arr[ind] = x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment