Skip to content

Instantly share code, notes, and snippets.

@alvinmatias69
Created April 17, 2018 17:51
Show Gist options
  • Save alvinmatias69/71eddaa4a834a27422836015f515cf01 to your computer and use it in GitHub Desktop.
Save alvinmatias69/71eddaa4a834a27422836015f515cf01 to your computer and use it in GitHub Desktop.
#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