Created
April 17, 2018 17:51
-
-
Save alvinmatias69/71eddaa4a834a27422836015f515cf01 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
using namespace std; | |
int main () { | |
int arr[6] = {15, 14, 10, 7, 3}; | |
int insert = 9; | |
int found_idx = 0; | |
int idx = 0; | |
bool found = false; | |
while (not found and idx < 5) { | |
if (arr[idx] < insert) { | |
found = true; | |
found_idx = idx; | |
} | |
idx++; | |
} | |
for (idx=4; idx >= found_idx; idx--) { | |
arr[idx+1] = arr[idx]; | |
} | |
arr[found_idx] = insert; | |
return found_idx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment