Solution to Problem 1
// Assumes that size of list is at least 1 when it is sent into the
// function
void removeDuplicates (Vector < int > & list)
{
int currentIndex = 1;
int filledSlot = 0;
int size = list.length();
while (currentIndex < size)
{
if (list[filledSlot] != list[currentIndex])
{
filledSlot++;
list[filledSlot] = list[currentIndex];
}
currentIndex++;
}
list.SetSize(filledSlot+1);
}
Solution to Problem 2
#include <iostream.h >
#include "vector.h"
int main()
{
cout <<< "Type the value of N: ";
cin >> N;
Vector < int > sieve(N+1, 1);
for (i = 2; i < N+1; i++)
{
if (sieve[i])
{
cout << i << endl;
for (j = 1; j*i < N+1; j++)
sieve[j*i] = 0;
}
}
return 0;
}