当前位置: 首页>>代码示例>>C++>>正文


C++ DoublyLinkedList::add方法代码示例

本文整理汇总了C++中DoublyLinkedList::add方法的典型用法代码示例。如果您正苦于以下问题:C++ DoublyLinkedList::add方法的具体用法?C++ DoublyLinkedList::add怎么用?C++ DoublyLinkedList::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DoublyLinkedList的用法示例。


在下文中一共展示了DoublyLinkedList::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:msf12,项目名称:Division-3,代码行数:60,代码来源:DatabaseCodeTesting2.cpp

示例2: main

int main(int argc, char const *argv[])
{
	DoublyLinkedList<FileInfo> d;

	FileInfo test;
	test.fileName[0] = '.';
	test.fileName[1] = '_';
	test.fileName[2] = '.';
	test.fileName[3] = 'T';
	test.fileName[4] = 'r';
	test.fileName[5] = 'a';
	test.fileName[6] = 's';
	test.fileName[7] = 'h';
	test.fileName[8] = 'e';
	test.fileName[9] = 's';
	test.fileName[10] = '\0';
	test.index = 96;
	d.add(test);

	FileInfo test2;
	test2.fileName[0] = '.';
	test2.fileName[1] = 'T';
	test2.fileName[2] = 'r';
	test2.fileName[3] = 'a';
	test2.fileName[4] = 's';
	test2.fileName[5] = 'h';
	test2.fileName[6] = 'e';
	test2.fileName[7] = 's';
	test2.fileName[8] = '\0';
	test2.index = 192;
	d.add(test2);

	FileInfo test3;
	test3.fileName[0] = '.';
	test3.fileName[1] = 'S';
	test3.fileName[2] = 'p';
	test3.fileName[3] = 'o';
	test3.fileName[4] = 't';
	test3.fileName[5] = 'l';
	test3.fileName[6] = 'i';
	test3.fileName[7] = 'g';
	test3.fileName[8] = 'h';
	test3.fileName[9] = 't';
	test3.fileName[10] = '-';
	test3.fileName[11] = 'V';
	test3.fileName[12] = '1';
	test3.fileName[13] = '0';
	test3.fileName[14] = '0';
	test3.fileName[15] = '\0';
	test3.index = 288;
	d.add(test3);

	FileInfo test4;
	test4.fileName[0] = '.';
	test4.fileName[1] = 'f';
	test4.fileName[2] = 's';
	test4.fileName[3] = 'e';
	test4.fileName[4] = 'v';
	test4.fileName[5] = 'e';
	test4.fileName[6] = 'n';
	test4.fileName[7] = 't';
	test4.fileName[8] = 's';
	test4.fileName[9] = 'd';
	test4.fileName[10] = '\0';
	test4.index = 352;
	d.add(test4);

	FileInfo test5;
	test5.fileName[0] = 'L';
	test5.fileName[1] = 'O';
	test5.fileName[2] = 'S';
	test5.fileName[3] = 'T';
	test5.fileName[4] = '.';
	test5.fileName[5] = 'D';
	test5.fileName[6] = 'I';
	test5.fileName[7] = 'R';
	test5.fileName[8] = '\0';
	test5.index = 384;
	d.add(test5);

	FileInfo test6;
	test6.fileName[0] = '.';
	test6.fileName[1] = 'a';
	test6.fileName[2] = 'n';
	test6.fileName[3] = 'd';
	test6.fileName[4] = 'r';
	test6.fileName[5] = 'o';
	test6.fileName[6] = 'i';
	test6.fileName[7] = 'd';
	test6.fileName[8] = '_';
	test6.fileName[9] = 's';
	test6.fileName[10] = 'e';
	test6.fileName[11] = 'c';
	test6.fileName[12] = 'u';
	test6.fileName[13] = 'r';
	test6.fileName[14] = 'e';
	test6.fileName[15] = '\0';
	test6.index = 480;
	d.add(test6);

//.........这里部分代码省略.........
开发者ID:msf12,项目名称:Division-3,代码行数:101,代码来源:DoublyLinkedList.cpp


注:本文中的DoublyLinkedList::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。