/** Insert Eratosthenes Sieve @brief inserts primes into an array using the Sieve of Eratosthenes @param upperBound the maximum for the prime numbers @param arrayCreation the array to insert primes into */ void insertEratosthenesSieve(int upperBound, SortSetArray &arrayCreation){ int upperBoundSquareRoot = (int) sqrt((double) upperBound); bool *isComposite = new bool [upperBound + 1]; memset(isComposite, 0, sizeof(bool) * (upperBound + 1)); for (int cycle = 2; cycle <= upperBoundSquareRoot; cycle++){ if (!isComposite[cycle]){ arrayCreation.insert(cycle); for (int marker = cycle*cycle; marker <= upperBound; marker += cycle ){ isComposite[marker] = true; }//end for marker }//end if !isComposite }//end for for (int cycle = upperBoundSquareRoot; cycle <= upperBound; cycle++){ if (!isComposite[cycle]) arrayCreation.insert(cycle); }//end for cycle2 delete [] isComposite; }//end insertEratosthenesSieve
/** Operator overload for +. It will create a returning unionSet SortSetArray. The union will contain union of all numbers in the two arrays. @param bSet the target array that you want to have a union with. @retun unionSet that contains the union of the two arrays. */ SortSetArray SortSetArray::operator+(const SortSetArray& bSet)const { SortSetArray unionSet = *this; for (int i=0; i < bSet.getSize(); i++) { if (bSet.setArray[i] >= 0 || this->setArray[i] >= 0) { unionSet.insert(this->setArray[i]); unionSet.insert(bSet.setArray[i]); } } return unionSet; }
void insertFibs(const int maxEntered, SortSetArray &emptyList){ for (int cycle = 0; cycle <= maxEntered; cycle++) { int calculatedFib = fib(cycle); emptyList.insert(calculatedFib); }//end for }//end insertFibs
/** Operator overload for *. It will create a returning intersection SortSetArray. The intersection will contain the numbers that appears in both the given arrays. @param bSet the target array that you want to have a intersection with. @retun intersectionSet that contains the intersection of the two arrays. */ SortSetArray SortSetArray::operator*(const SortSetArray& bSet)const { SortSetArray intersectionSet; for (int i=0; i < bSet.getSize(); i++) { if (bSet.setArray[i] >= 0 && bSet.setArray[i] == this->setArray[i]) { intersectionSet.insert(bSet.setArray[i]); } } return intersectionSet; }