本文整理汇总了C++中HashTable::getList方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::getList方法的具体用法?C++ HashTable::getList怎么用?C++ HashTable::getList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::getList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
//create_stu();
welcome();
command_tips();
cout << endl;
srand(time(0));
HashTable<Student> h;
HashTable2<Student> table;
//read_stu(h, table);
string command;
while(cin >> command) {
if (command[0] == '$') {
if (command[1] == 'Q') break;
switch(command[1]) {
case 'I':
{
cout << "Please input a student's information (ID, name, age, gender):" << endl;
string id, name;
int age;
bool sex;
cin >> id >> name >> age >> sex;
Student student(id, name, age, sex);
if (h.insert(student)) {
cout << "\nInserted successfully: " << endl; //print the information that is removed
cout << "Name: " << student.getName() << endl;
cout << "ID: " << student.getID() << endl;
cout << "Age: " << student.getAge() << endl;
cout << "Gender: " << (student.getSex() == 0? "Male":"Female") << endl << endl;
} else {
cout << "\nInserted failed: The system already contains the student" << endl;
}
}
break;
case 'R':
{
cout << "Please input the student's ID:" << endl;
string s2;
cin >> s2;
h.remove(s2);
cout << endl;
}
break;
case 'F':
{
cout << "Please input the student's ID:" << endl;
string s2;
cin >> s2;
h.findKey(s2);
cout << endl;
}
break;
case 'T':
{
cout << "Please wait for inputing the information from the file." << endl;
read_stu(h, table);
cout << "Input finished" << endl;
cout << "Tatal numbers of student: " << totalNumber << endl;
vector<list<Student> > ve = h.getList();
double ave_CHI = 0, ave_OPEN = 0;
int num = 30;
for (int i = 0; i < num; i++) {
list<Student>::iterator p = ve[rand() % ve.size()].end();
string s1 = (*(--p)).getID();
double CHAIN, OPEN;
ave_CHI += (double)h.cal_time(s1) ;
ave_OPEN += (double)table.cal_time(s1);
cout << "chaning: " << setw(8) << (double)h.cal_time(s1) << " s" << " open addressing: " << setw(8) << (double)table.cal_time(s1) << " s" << endl;
Sleep(100);
}
cout << "Average time with chaining: " << (double)(ave_CHI / num) << " s"<< endl;
cout << "Average time with open addressing: " << (double)(ave_OPEN / num) << " s" << endl;
cout << endl;
} break;
default:
{
cout << "Command error! Please enter a right command!" << endl;
command_tips();
} break;
}
} else {
cout << "Command error! Please enter a right command!" << endl;
command_tips();
}
}