本文整理汇总了C++中WordList::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::insert方法的具体用法?C++ WordList::insert怎么用?C++ WordList::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WordList
的用法示例。
在下文中一共展示了WordList::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
ofstream log; // to record log file
log.open("log.txt", std::fstream::app);
CommandLineParser clp(argv[1],','); //instantiating the class CommandLineParser
if (argc == 1)
{
log << "Error: no argument is passed.\n" << endl;
log.close();
return -1;
}
//use CommandLineParser to get the script name
char *script = clp.extract("script");
if (script == NULL || *script == '\0')
{
log << "Error: no script file specified.\n" << endl;
log.close();
return -1;
}
//use ScriptParser to get the commands from script file
ScriptParser SParser = ScriptParser();
ifstream indata(script);
if (!indata.is_open()) // check if script file is correctly opened.
{
log << "Error: Script file \'" << script << "\' cannot be opened or does not exist.\n" << endl;
log.close();
return -1;
}
//start parsing script file
int i = 0;
int n;
int size;
int k;
string line; // store each line in script file
WordList *L; // array of word lists
FreqList *F; // array of frequency lists which store the information of words and its frequency
string *S; // array of strings which store the name of lists
Hash HT; // hash table to store all the words
L = new WordList[1000];
F = new FreqList[1000];
S = new string[1000];
//initiate temporary lists and list nodes
WordNode *tempWordNode;
FreqNode *tempFreqNode;
WordList tempWordList;
WordList *tempWordListpt;
FreqList tempFreqList;
FreqList tempFreqList2;
string tempString;
Node *tempNode;
int pos1;
int pos2;
log << "Begin parsing script file \'" << script << "\':\n" << endl;
while(getline(indata, line))
{
log << line << '\n';
SParser.ParseLine(line);
//process to determine if listID exits
int ID = -1; // cmd.listID, after following checking process, if it's still -1, then cmd.listID is a new list, otherwise cmd.listID is the word list L[ID] or frequency list F[ID]
int ID2 = -1; // cmd.value1 (if it stores list name), same procesure as above
int ID3 = -1; // cmd.value2 (if it stores list name), same procesure as above
for (int j = 0; j < i; j++)
{
ID = (SParser.cmd.listID == S[j])?j:ID; // check if cmd.listID is already in S[]
}
if (SParser.operationCode() != 3 && SParser.operationCode() != 8 && SParser.operationCode() != 9 && SParser.operationCode() != 10 && SParser.operationCode() != 13 && SParser.operationCode() != 0 && ID == -1)
{
log << "Error: invalid operation, because list \'" << SParser.cmd.listID << "\' is not created yet.\n" << endl;
if (SParser.operationCode() == 4 || SParser.operationCode() == 5)
{
ofstream output;
output.open(SParser.cmd.value1.c_str());
output << "List " << SParser.cmd.listID << " does not exist" << endl;
output.close();
}
continue;
}
if ((SParser.operationCode() == 3 || SParser.operationCode() == 8 || SParser.operationCode() == 9 || SParser.operationCode() == 10 || SParser.operationCode() == 13) && ID > -1)
{
log << "Error: invalid operation, because list \'" << SParser.cmd.listID << "\' already exists.\n" << endl;
continue;
}
// do all the list operations, such as read, insert, delete, write, intersection, union, load, filter, index and seach
switch (SParser.operationCode())
{
case 1:
n = L[ID].insert(SParser.cmd.value2, SParser.cmd.value1);
if (n == -1) {
//.........这里部分代码省略.........