⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testlinkset.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -