finished hw5

This commit is contained in:
2019-10-21 23:26:32 -06:00
parent a768bb692d
commit 672bd8313d
220 changed files with 24769 additions and 15000 deletions

View File

@@ -1,42 +1,56 @@
#include "WordTree.hpp"
#include "rlutil.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
int main()
{
WordTree mytree;
std::shared_ptr<WordTree> tree = mytree.readDictionary("dictionary.txt");
// mytree.add("whats");
// mytree.add("up");
// mytree.add("mother");
// mytree.add("fucker");
//tree->readDictionary("dictionary.txt");
std::string input;
while ()
int position = 0;
while (true)
{
auto tmp = rlutil::getkey();
switch (tmp)
{
case rlutil::KEY_BACKSPACE:
{
if (!input.empty())
{
input.erase(input.size());
}
}
case rlutil::KEY_DELETE:
{
std::cout << "IM HERE" << std::endl;
input.clear();
}
default:
{
rlutil::setChar(tmp);
input += tmp;
rlutil::cls();
rlutil::locate(0, 0);
if (tmp == rlutil::KEY_BACKSPACE)
{
if (!input.empty())
{
input.pop_back();
position--;
}
}
}
else if (tmp == rlutil::KEY_DELETE)
{
input.clear();
position = 0;
}
else if ((tmp >= 'a' && tmp <= 'z') || " ")
{
input += tmp;
position++;
}
std::cout << input << std::endl;
std::cout << "Hello, World!" << std::endl;
int i = input.length() - 1; // last character
while (i != 0 && !isspace(input[i]))
{
--i;
}
std::string lastword = input.substr(i + 1);
auto words = tree->predict(lastword, rlutil::trows() - 3);
std::cout << "-----prediction-----" << std::endl;
for (auto word : words)
{
std::cout << word << std::endl;
}
rlutil::locate(position + 1, 0);
}
return 0;
}
#pragma clang diagnostic pop