Created
June 26, 2012 07:17
-
-
Save vcwu/2994038 to your computer and use it in GitHub Desktop.
SimplifyTester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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