本文整理汇总了C++中AVL::lookup方法的典型用法代码示例。如果您正苦于以下问题:C++ AVL::lookup方法的具体用法?C++ AVL::lookup怎么用?C++ AVL::lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVL
的用法示例。
在下文中一共展示了AVL::lookup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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: main
//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;
}