testlinkset.cpp
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 84 行
CPP
84 行
#include <iostream>
#include <string>
#include <cctype> // for tolower
using namespace std;
#include "linkstringset.h"
#include "prompt.h"
void Print(const LinkStringSet& set)
{
LinkStringSetIterator it(set);
cout << "----------" << endl;
for(it.Init(); it.HasMore(); it.Next())
{ cout << it.Current() << endl;
}
cout << "---------- size = " << set.size() << endl;
}
void Help()
{
cout << "(h)elp print help" << endl;
cout << "(i)insert word into set" << endl;
cout << "(c)lear set" << endl;
cout << "(e)rase word from set" << endl;
cout << "(p)rint the set and size" << endl;
cout << "(s)earch for word in set" << endl;
cout << "(q)uit program" << endl;
cout << "---" << endl;
}
void TestSet()
{
string word, commandLine;
LinkStringSet set;
char command = 'h';
while (command != 'q')
{ commandLine = PromptlnString("enter command : ");
if (commandLine == "")
{ command = 'h';
}
else
{ command = tolower(commandLine[0]);
}
switch (command)
{
case 'h' :
Help();
break;
case 'i' :
word = PromptlnString("enter word : ");
set.insert(word);
break;
case 'c':
set.clear();
break;
case 'e':
word =PromptlnString("enter word : ");
set.erase(word);
break;
case 'p':
Print(set);
break;
case 's':
word = PromptlnString("enter word : ");
if (set.contains(word))
{ cout << word << " was found" << endl;
}
else
{ cout << word << " was NOT found" << endl;
}
case 'q':
break;
default:
cout << "unrecognized command" << endl;
break;
}
}
}
int main()
{
TestSet();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?