예제 #1
0
파일: main.cpp 프로젝트: mboghiu/try
int main()
{
    while (true)
    {
        ///////////// Read user input ////////////

        std::string command, value;
        size_t key;

        utils::read_input<size_t, std::string>(std::cin, command, key, value);

        ///////////// Process ///////////

        switch (utils::str2enum(command))
        {
            case options::LS:
            {
                g_avl.Print();
                break;
            }

            case options::ADD:
            {
                g_avl.insert(key, value);
                break;
            }

            case options::RM:
            {
                g_avl.remove(key);
                break;
            }

            case options::GET:
            {
                try
                {
                    std::cout << key << " = " << g_avl.lookup(key) << std::endl;
                }
                catch (const std::string& e)
                {
                    std::cout << "error: " << e << std::endl;
                }

                break;
            }

            case options::Q: { exit(0); break; }
            
            case options::UNKNOWN: { break; }
        }
    }

    return 0;
}
예제 #2
0
//I used a .txt filled with employees names and ID numbers to create the AVL binary tree.
int main() 
{
    std::string file_name = "data/employees.txt";
    std::ifstream in_file(file_name);
    
    AVL <std::string, std::string> EmployeeData;
    
    //Parse the employee names and idss out of the text file
    std::string line;
    while(std::getline(in_file,line)) 
    {
        // Gets the employees name
        std::string employee_name = line.substr(0,line.find(","));
        // Gets the employees id number
        std::string employee_id = line.substr(line.find(",")+1);
        EmployeeData.insert(employee_name, employee_id);
    }
    //EmployeeData.Delete(EmployeeData.root, "Zyon Newman");
    EmployeeData.print(EmployeeData.root);
    std::cout << "Testing Lookup" << std::endl;
    std::cout << "Zyler Whitney: " << EmployeeData.lookup(EmployeeData.root, "Zyler Whitney") << std::endl;

    return 0;
}