int main() { LList<int> llist; LList<int>::iterator it = llist.begin(); LList<int>::iterator it2 = llist.end(); it2 = LList<int>::iterator(it); #if 1 it = llist.insert(it,1); it = llist.insert(it,2); it = llist.insert(it,3); it = llist.begin(); cout<<"--------insert-------------"<<endl; for(;it != llist.end();it++) cout<<*it<<endl; llist.clear(); llist.push_back(11); llist.push_back(12); llist.push_back(13); llist.erase(llist.begin()); cout<<"--------push_back-------------"<<endl; for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; llist.clear(); cout<<"--------size-------------"<<llist.size()<<endl; llist.push_back(14); llist.push_back(15); llist.push_back(16); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; cout<<"--------transfer-------------"<<llist.size()<<endl; LList<int>::iterator first= ++llist.begin(); LList<int>::iterator last= llist.end(); llist.transfer(++llist.begin(),++first,last); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; cout<<"--------reverse-------------"<<llist.size()<<endl; llist.reverse(); for(it=llist.begin();it != llist.end();it++) cout<<*it<<endl; #endif return 0; }
int main() { LList<Pokemon> pokedex; pokedex.push_back(Pokemon(1, "Bulbasaur")); pokedex.push_back(Pokemon(4, "Charmander")); pokedex.push_back(Pokemon(7, "Squirtle")); for (int i = 0; i < pokedex.size(); i++) { std::cout << pokedex.get(i).name << std::endl; } return 0; }
void LList::Oplus(LList& L1) { int i,j,k,pos; int AddDim = L1.size(); int OldDim = dim; int OldClassSize=0; if (OldDim!=0) OldClassSize = data[0].Gname.size(); LevelArray OldBody; Level TmpLevel; if (OldDim != 0) { OldBody.assign(OldDim+1,TmpLevel); for (i=0;i<=OldDim;i++) { OldBody[i].Gname.assign(OldClassSize,1); for (j=0;j<OldClassSize;j++) OldBody[i].Gname[j] = data[i].Gname[j]; OldBody[i].Gnr = data[i].Gnr; } } dim = (AddDim+1)*(OldDim+1) - 1; data.assign(dim+1,TmpLevel); pos=0; for (i=0;i<=OldDim;i++) { for (j=0;j<=AddDim;j++) { data[pos].Gname.assign(OldClassSize+1,1); if (OldDim!=0) for (k=0;k<OldClassSize;k++) data[pos].Gname[k] = OldBody[i].Gname[k]; data[pos].Gname[OldClassSize] = L1[j]->Gname[0]; if (OldDim!=0) data[pos].Gnr = OldBody[i].Gnr + L1[j]->Gnr; else data[pos].Gnr = L1[j]->Gnr; pos++; } } OldBody.erase(OldBody.begin(),OldBody.end()); }
void ParseMemoryLeakFile(const char *_inputFilename, const char *_outputFilename) { /* */ /* Start up */ /* */ RedBlackTree<char *, int> combined; RedBlackTree<char *, int> frequency; int unrecognised = 0; /* */ /* Open the file and start parsing */ /* */ FILE *memoryfile = fopen(_inputFilename, "rb"); while (memoryfile && !feof(memoryfile)) { char thisline[1024]; fgets(thisline, 1024, memoryfile); if (!strncmp(thisline, " Data:", 6) == 0) { /* This line is a data line - useless to us */ if (strchr(thisline, ':')) { /* This line does not have a source file location - useless to us */ /* Get the size */ char *lastcomma = strrchr(thisline, ','); if (lastcomma == 0) continue; char *ssize = lastcomma + 2; int size; char unused[32]; sscanf(ssize, "%d %s", &size, unused); /* Get the source file name */ char *sourcelocation = thisline; char *colon = strrchr(thisline, ':'); *(colon - 1) = '\x0'; /* Put the result into our BTree */ int result = 0; bool found = combined.find(sourcelocation, result); if (found) combined.replace(sourcelocation, result + size); else combined.insert(sourcelocation, size); found = frequency.find(sourcelocation, result); if (frequency.exists(sourcelocation)) frequency.replace(sourcelocation, result + size); else frequency.insert(sourcelocation, 1); } else { char *lastcomma = strrchr(thisline, ','); if (lastcomma) { char *ssize = lastcomma + 2; int size; char unused[32]; sscanf(ssize, "%d %s", &size, unused); unrecognised += size; } } } } fclose(memoryfile); /* */ /* Sort the results into a list */ /* */ LList<char *> sorted; DArray<char *> *dataI = combined.ConvertIndexToDArray(); DArray<int> *dataD = combined.ConvertToDArray(); int totalsize = 0; for (size_t i = 0; i < dataI->size(); i++) { if (dataI->valid(i)) { char *newsource = dataI->get(i); int newsize = dataD->get(i); totalsize += newsize; bool inserted = false; for (size_t i = 0; i < sorted.size(); i++) { char *existingsource = sorted.get(i); int existingsize; combined.find(existingsource, existingsize); if (newsize <= existingsize) { sorted.insert_at(newsource, i); inserted = true; break; } } if (!inserted) sorted.insert(newsource); } } delete dataI; delete dataD; /* */ /* Open the output file */ /* */ if (sorted.size()) { FILE *output = fopen(_outputFilename, "wt"); /* */ /* Print out our sorted list */ /* */ fprintf(output, "Total recognised memory leaks : %d Kbytes\n", int( totalsize / 1024 )); fprintf(output, "Total unrecognised memory leaks : %d Kbytes\n\n", int( unrecognised / 1024 )); for (int k = (int)sorted.size() - 1; k >= 0 && k < (int)sorted.size(); k--) { char *source = sorted.get(k); CoreAssert(source); int size; combined.find(source, size); int freq; frequency.find(source, freq); if (size > 1048576) { fprintf(output, "%-95s (%d MB in %d leaks)\n", source, int( size / 1048576 ), freq); } else if (size > 2048) { fprintf(output, "%-95s (%d KB in %d leaks)\n", source, int( size / 1024 ), freq); } else { fprintf(output, "%-95s (%d bytes in %d leaks)\n", source, size, freq); } } /* */ /* Clean up */ fclose(output); } }