Skip to content

Instantly share code, notes, and snippets.

@NickersF
Created January 24, 2016 01:03
Show Gist options
  • Save NickersF/545ca86f544ca1d377aa to your computer and use it in GitHub Desktop.
Save NickersF/545ca86f544ca1d377aa to your computer and use it in GitHub Desktop.
C++ Remove Integer From Array
// this function removes a given element from the array in this program
bool remove(int val, int intList[], int& size) {
int index;
bool found = false;
for (int i = 0; i < size; i++) {
if (val == intList[i]) {
found = true;
index = i;
cout << "Value " << intList[i] << " found at index [ " << i << " ]" << endl;
break;
}
if (!found) {
cout << "Value not found." << endl;
}
}
for (int i = index; i < size -1; i++) {
intList[i] = intList[i + 1];
}
size--;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment