Skip to content

Instantly share code, notes, and snippets.

@vcwu
Created June 26, 2012 07:17
Show Gist options
  • Select an option

  • Save vcwu/2994038 to your computer and use it in GitHub Desktop.

Select an option

Save vcwu/2994038 to your computer and use it in GitHub Desktop.
SimplifyTester
long Poly::simplifyTester()
{
long time = 0;
list<term>* p = this->getTerms();
list<term>* tempList = new list<term>();
if(!p->empty())
{
//STL::sort is given as O(n log n).
p->sort();
long size = p->size();
time += size* (size * log10((float)size) );
list<term>::iterator it = p->begin();
list<term>::iterator seek = it;
seek++;
int newCoeff = it->coeff;
//Iterate through the list.
time += size;
while(seek != p->end())
{
if(term::equalExponents(*it, *seek))
{
newCoeff += seek->coeff;
}
else
{
term t(newCoeff, it->getExp(1), it->getExp(2),it->val1, it->val2);
it = seek;
tempList->push_back(t);
newCoeff = it->coeff;
}
seek++;
}
term t(newCoeff, it->getExp(1), it->getExp(2), it->val1, it->val2);
tempList->push_back(t);
}
return time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment