1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
using namespace std;
void removeNumber(int numbers[], int idx, int &size)
{
int i;
for(i = idx; i < size - 1; i++)
numbers[i] = numbers[i + 1];
size--;
}
void removeDuplicate(int numbers[], int &size)
{
int i, j;
int number;
for(i = 0; i < size; i++)
{
number = numbers[i];
for(j = i + 1; j < size; j++)
{
if(number == numbers[j])
{
removeNumber(numbers, j, size); j--;
}
}
}
}
int main()
{
int i;
int numbers[] = { 1,4,9,16,9,7,4,9,4,11 };
int size = 10;
removeDuplicate(numbers, size);
for(i = 0; i < size; i++)
cout << numbers[i] << ' '; cout << endl;
system("pause");
return 0;
}
|