Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frmsaul/91154a63ddf574e0ab06 to your computer and use it in GitHub Desktop.
Save frmsaul/91154a63ddf574e0ab06 to your computer and use it in GitHub Desktop.
"C++ code to insert an element into middle of array"
//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