I created the void AllPrimes function to display all the primes numbers. However, I need it to display the Prime numbers in ascending order. Right now it displays them in descending order.
size_t PrimeBelow (size_t n, bool ticker)
// returns largest prime number <= n
{
if (n <= 1) return 0;
if (n == 2) return 2;
if (n >= n+1)
{
std::cerr << " ** PrimeBelow: argument too large for implementation. Execution terminating.\n";
exit (EXIT_FAILURE);
}
fsu::BitVector b(1+n);
Sieve(b, ticker);
if (n%2 == 0) --n; // make n odd
while (n > 2)
{
if (b[n])
return n;
n -= 2;
}
return 2;
}
Since your code creates primes in descending order, if you can use a std::vector as storage there is no need to sort the container. Simply start the output at the end of the vector and reverse loop through the elements.