hash table小小笔记

雜湊表( hash table )。元素的索引值由特殊方法決定,是一種特殊的歸類。

  1. int hash(int n// 根據元素的數值來製造一個index
  2. {
  3.     return n * 97 % 100;
  4. }
  5.  
  6. void hash_table()
  7. {
  8.     int array[5] = {36981};
  9.  
  10.     int table[100];
  11.     for (int i=0i<5i++)
  12.     {
  13.         // 替array[i]製造一個index
  14.         int index = hash(array[i]);
  15.  
  16.         // 將array[i]放入hash table
  17.         table[index] = array[i];
  18.     }
  19. }

posted @ 2010-10-28 15:24  hailong  阅读(91)  评论(0编辑  收藏  举报