本文整理汇总了C++中DoublyLinkedList::clearList方法的典型用法代码示例。如果您正苦于以下问题:C++ DoublyLinkedList::clearList方法的具体用法?C++ DoublyLinkedList::clearList怎么用?C++ DoublyLinkedList::clearList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoublyLinkedList
的用法示例。
在下文中一共展示了DoublyLinkedList::clearList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: splitDatabase
//reads a subset of database determined by memory capacity into a DoublyLinkedList
//subsequently sorts the list, iterates through it to merge entries with duplicate primary fields separated by delim
//and concatenate secondary fields using conn as the separator
//and exports it into a temp file
//returns the count of temporary files
int splitDatabase(string &database, const char delim, const char conn)
{
ifstream fin(database);
ofstream fout;
int tempFileCount = 0;
for (char buffer[LINE_BUFFER_SIZE]; fin.getline(buffer,LINE_BUFFER_SIZE,'\n');)
{
static int charsRead;
static string tempFileName = string("temp") + to_string(tempFileCount++) + ".db";
static string lineRead = "";
static DoublyLinkedList<string> lines;
lineRead += buffer;
charsRead += fin.gcount();
//if \n was not found by getline
if(fin.fail())
{
fin.clear();
}
else
{
lines.add(lineRead);
lineRead = "";
if(charsRead > CHARS_ALLOWED_IN_MEMORY || fin.eof())
{
fout.open(tempFileName);
lines.sort();
for (DoublyLinkedList<string>::iterator iter = lines.begin(), jter = iter.next();
!iter.isNull(); iter = jter, jter = iter.next())
{
//if jter is not a null node
//and the first field of iter (iter[0] -> iter.find(delim)) is equal to the first field of jter
//append the second field of jter to the second field of iter separated by conn
//repeat until the first fields differ or jter goes out of the bounds of the list
while(!jter.isNull() && (*iter).substr(0,(*iter).find(delim)) == (*jter).substr(0,(*jter).find(delim)))
{
*iter += conn + (*jter).substr((*jter).find(delim)+1);
++jter;
}
//store iter in the current temporary database file
fout << *iter << endl;
}
fout.close();
tempFileName = string("temp") + to_string(tempFileCount++) + ".db";
lines.clearList();
charsRead = 0;
}
}
}
fin.close();
return tempFileCount-1;
}