📄 e08-01.cpp
字号:
// =======================================================
// Chapter 8, Example 1
// Using the Hash Table
// =======================================================
#include "HashTable.h"
#include <iostream.h>
unsigned long int Hash( int k )
{
return k;
}
void main()
{
int size;
int choice = 1;
int key;
int data;
cout << "Enter the size of the table: ";
cin >> size;
HashTable<int, int> table( size, Hash );
HashEntry<int, int>* entry;
while( choice != 0 )
{
cout << endl;
cout << "0 - Quit" << endl;
cout << "1 - Insert data" << endl;
cout << "2 - Find key" << endl;
cout << "3 - Remove key" << endl;
cout << "Your Choice: ";
cin >> choice;
cout << endl;
switch( choice )
{
case 1:
cout << "Key: ";
cin >> key;
cout << "Data: ";
cin >> data;
table.Insert( key, data );
cout << "Inserted (" << key << ", " << data << ")" << endl;
break;
case 2:
cout << "Key: ";
cin >> key;
entry = table.Find( key );
if( entry == 0 )
{
cout << "Key not found!" << endl;
}
else
{
cout << "Data Found: (" << entry->m_key << ", ";
cout << entry->m_data << ")" << endl;
}
break;
case 3:
cout << "Key: ";
cin >> key;
entry = table.Find( key );
if( entry == 0 )
{
cout << "Key not found!" << endl;
}
else
{
cout << "Data Removed: (" << entry->m_key << ", ";
cout << entry->m_data << ")" << endl;
}
table.Remove( key );
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -