void TimeComplexity::union_tracktime(string listname1, string listname2, string listname3) { time_actual = 0; long n_1 = all_lists->getN(listname2); long n_2 = all_lists->getN(listname3); long n_low, n_hi; if(n_1 > n_2) { n_low = n_2; n_hi = n_1; } else { n_low = n_1; n_hi = n_2; } //union's algorithm 5*(n_low + n_low*n_low+ n_hi*n_hi) how I got 5 is in the README long tc_estimate = 5*(n_low + n_low*n_low+ n_hi*n_hi); long c = 8; long upper_bound = c*((n_hi*n_hi) + (n_low*n_low)); // n^2 is the upper bound or O(n^2), since bubble sort is used to alphabetize all_lists->union_initialize(listname3, listname2, listname1, "iterative"); // calling the actual union function to calculate the TIME_ACTUAL stringstream ss; //outputting all data in CSV format ss<<n_1<<","<<n_2<<","<<"union,"<<tc_estimate<<","<<time_actual<<","<<c<<",64,"<<upper_bound; string result = ss.str(); output(result, "append"); return; }
int main() { vector<int> k; for(int j = 0; j < 10; ++j) { k.push_back(j); } VectorContainer test (k); test.print(); cout << test.at(3) << endl; cout << "should be 3" << endl; test.swap(0,1); test.print(); test.size(); test.insert(15); test.print(); cout << "break" << endl; list <int> l; for(int j = 0; j < 10; ++j) { l.push_back(j); } ListContainer testlst (l); testlst.print(); cout << testlst.at(3) << endl; cout << "should be 3" << endl; testlst.swap(0,1); testlst.print(); testlst.size(); testlst.insert(15); testlst.print(); return 0; }
TextureData::~TextureData(void) { if(textureId != -1) glDeleteTextures( 1, &textureId ); Textures.Remove(this); }
void TreeContainer::check(string new_list, string old_list) //creates a new_list of the incorrectly spelled words out of the old_list { ListNode *oldlist = all_lists->find_list(old_list); ListNode *newlist = new ListNode; newlist->listID = new_list; Node *current = oldlist->list.head; while(current != NULL) { if(!search(current->word)) newlist->list.addWord(current->word, current->cleaned_word, current->count, current->punc_count); current = current->next; } all_lists->add_list(newlist); }
TextureData* TextureData::FromDDS(char* source) { Textures.InitReader(); while(Textures.Read()) { if(strcasecmp(Textures.Cur->Name,source)) return Textures.Cur; } TextureData* Texture = new TextureData(); Texture->CreateData(); DDSLoader::loadDds(source); strcpy(Texture->Name,source); //Textures.Add(textureData); return Texture; }
TextureData::TextureData(void) { //Textures = ListContainer(); textureId = -1; // Add to texture list Textures.Add(this); }
int main() { // srand(time(NULL)); //vector bubble sort cout << "vector bubble sort" << endl; VectorContainer vc; SortAlgorithm* bs = new BubbleSort(); cout << "BEFORE: "; vc.print(); vc.set_sort(bs); vc.sort(); vc.print(); cout << endl; //vector selection sort cout << "vector seleciton sort" << endl; VectorContainer vc1; SortAlgorithm* ss = new SelectionSort(); cout << "BEFORE: "; vc1.print(); vc1.set_sort(ss); vc1.sort(); vc1.print(); //vector merge sort cout << "vector merge sort" << endl; VectorContainer vc2; SortAlgorithm* ms = new MergeSort(); cout << "BEFORE: "; vc2.print(); vc2.set_sort(ms); vc2.sort(); vc2.print(); cout << endl; //filled vector bubble sort cout << "filled vector bubble sort" << endl; VectorContainer vc3; SortAlgorithm* bs1 = new BubbleSort(); cout << "BEFORE: "; vc3.randHun(20); vc3.print(); vc3.set_sort(bs1); vc3.sort(); vc3.print(); cout << endl; //filled vector selection sort cout << "filled vector selection sort" << endl; VectorContainer vc4; SortAlgorithm* ss1 = new SelectionSort(); cout << "BEFORE: "; vc4.randHun(20); vc4.print(); vc4.set_sort(ss1); vc4.sort(); vc4.print(); cout << endl; //filled vector merge sort cout << "filled vector merge sort" << endl; VectorContainer vc5; SortAlgorithm* ms1 = new MergeSort(); cout << "BEFORE: "; vc5.randHun(20); vc5.print(); vc5.set_sort(ms1); vc5.print(); cout << endl; //list bubble sort cout << "list bubble sort" << endl; ListContainer lc; SortAlgorithm* bs2 = new BubbleSort(); cout << "BEFORE: "; lc.print(); lc.set_sort(bs2); lc.sort(); lc.print(); cout << endl; //list selection sort cout << "list seleciton sort" << endl; ListContainer lc1; SortAlgorithm* ss2 = new SelectionSort(); cout << "BEFORE: "; lc1.print(); lc1.set_sort(ss2); lc1.sort(); lc1.print(); cout << endl; //list merge sort cout << "list merge sort" << endl; VectorContainer lc2; SortAlgorithm* ms2 = new MergeSort(); cout << "BEFORE: "; lc2.print(); lc2.set_sort(ms); lc2.sort(); lc2.print(); cout << endl; //filled list buble sort cout << "list bubble sort" << endl; ListContainer lc3; SortAlgorithm* bs3 = new BubbleSort(); cout << "BEFORE: "; lc3.randHun(20); lc3.print(); lc3.set_sort(bs3); // lc3.sort(); lc3.print(); cout << endl; //filled list selection sort cout << "list selection sort" << endl; ListContainer lc4; SortAlgorithm* ss3 = new SelectionSort(); cout << "BEFORE: "; lc4.randHun(20); lc4.print(); lc4.set_sort(ss3); lc4.sort(); lc4.print(); cout << endl; //filled list merge sort cout << "list merge sort" << endl; ListContainer lc5; SortAlgorithm* ms3 = new MergeSort(); cout << "BEFORE: "; lc5.randHun(20); lc5.print(); lc5.set_sort(ms3); lc5.sort(); lc5.print(); cout << endl; delete bs; delete ms; delete ss; delete bs1; // delete ms1; // delete ss1; return 0; }
void StackContainer::postfixCalc(string listID) { Node* current = postfix_list->head; string s1, s2, itos; stringstream ss; int i = 0; while(current != NULL) { if(current->word == "+") { //creates a list named "union#" where # is an arbitrary iterator used to distinguish multiple unions in a single expression //pushes the name to the stack in order to use it for the next operation //However, if it is the last node in the list, it is the final operation which means the list should be instead named listID s1 = pop(); s2 = pop(); if(s1 == "" || s2 == "") { error("Stack underflow, not enough arguments for union for operation involving " +listID); break; } if(current->next == NULL) { all_lists->union_initialize(s1, s2, listID, "recursive"); break; } ss << i; itos = ss.str(); all_lists->union_initialize(s1, s2, "union"+itos, "recursive"); push("union"+itos); i++; current = current->next; ss.str(""); ss.clear(); continue; } if(current->word == "*") { //creates a list named "intersection#" where # is an arbitrary iterator used to distinguish multiple intersections in a single expression //pushes the name to the stack in order to use it for the next operation //however, if it is the last node in the list, it is the final operation which means the list should be instead named listID s1 = pop(); s2 = pop(); if(s1 == "" || s2 == "") { error("Stack underflow, not enough arguments for intersection for operation involving " +listID); break; } if(current->next == NULL) { all_lists->intersect_initialize(s1, s2, listID, "recursive"); break; } ss << i; itos = ss.str(); all_lists->intersect_initialize(s1, s2, "intersect"+itos, "recursive"); push("intersect"+itos); i++; current = current->next; ss.str(""); ss.clear(); continue; } //if not + or *, it must be an operand, and operands get pushed to stack push(current->word); current = current->next; i++; } while(pop()!=""); //clears the stack of anything left over if the expression was not legal }
// Generate Subtriangles for each Face void Brush::PerformIntersections(ListContainer<SimpleTriangle>* resultingTriangles) { ListContainer<SimpleTriangle>* subTriangles; if(!PerformedIntersections) { ListContainer<MapTriangle> IntersectionTriangles; IntersectionTriangles.PerformCleanup = false; ListContainer<MapTriangle>* curTriangles; bool isHidden; vec3 curCenter; float threshold = 0.01f; // Make a Local list with possible intersections IntersectingBrushes.InitReader(); while(IntersectingBrushes.Read()) { curTriangles = &IntersectingBrushes.Cur->Triangles; curTriangles->InitReader(); while(curTriangles->Read()) { IntersectionTriangles.Add(curTriangles->Cur); } } // Perform Operations Per Triangle Triangles.GetIndex(); for (int i = 0; i < Triangles.Length; i++) { Triangles.Index[i]->GenerateSubTriangles(&IntersectionTriangles); // Perform Operations Per Sub Triangle subTriangles = &Triangles.Index[i]->SubTriangles; subTriangles->GetIndex(); int currentLength = subTriangles->Length; for (int j = 0; j < currentLength; j++) { //Visibility Testing isHidden = false; curCenter = subTriangles->Index[j]->Center(); curCenter += subTriangles->Index[j]->Normal()*threshold; IntersectingBrushes.InitReader(); while (IntersectingBrushes.Read()) { if(IntersectingBrushes.Cur->PointTest(curCenter)) { subTriangles->RemoveDelete(subTriangles->Index[j]); break; } } } } PerformedIntersections = true; } // Return Subtriangles Triangles.InitReader(); while(Triangles.Read()) { subTriangles = &Triangles.Cur->SubTriangles; subTriangles->InitReader(); while(subTriangles->Read()) { resultingTriangles->Add(subTriangles->Cur->Copy()); } } }