雜湊表( hash table )。元素的索引值由特殊方法決定,是一種特殊的歸類。
- int hash(int n) // 根據元素的數值來製造一個index
- {
- return n * 97 % 100;
- }
- void hash_table()
- {
- int array[5] = {3, 6, 9, 8, 1};
- int table[100];
- for (int i=0; i<5; i++)
- {
- // 替array[i]製造一個index
- int index = hash(array[i]);
- // 將array[i]放入hash table
- table[index] = array[i];
- }
- }