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 44 45 46 47 48 49 50 51 52 53 54
|
template<typename T>
void delete_repeats(T a, int size)
{
int left = 0;
while (left < (size - 1))
{
int right = (left + 1);
while (right < size)
{
if (a[right] != a[left])
right++;
else
{
for (int i = right;i <= (size - 2);i++)
{
a[i] = a[i + 1];
}
size--;
}
}//end of right < size
left++;
}//end of left < size-1
}
template<typename P>
void printArray (P a, int size)
{//prints array}
}//end of delete_repeats
int main()
{
int a[100] = {2, 7, 1, 4, 3, 5, 2, 8, 9, 2, 5, 6, 4, 7, 8, 1, 2, 7};
printArray(a, size);
delete_repeats(a, size);
cout << endl;
printArray(a, size);
/*Set the value of variable left to 0
While the value of variable left is less than(size − 1)
Set the value of variable right to(left + 1)
While the value of variable right is less than the value of variable size
If a[right] is not equal to a[left]
Increment the value of variable right
Otherwise
For i = each value from right through & including(size − 2)
Set the value of a[i] to the value of a[i + 1]
Decrement the value of variable size
Increment the value of variable left*/
}
| |