Created
January 24, 2016 01:03
-
-
Save NickersF/545ca86f544ca1d377aa to your computer and use it in GitHub Desktop.
C++ Remove Integer From 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
// 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