// Solve the problem using separate chaining. #include // this table can have at most 1024 keys #define TABLE_SIZE 1024 class Node { public: int number; Node* next; }; // search the hash table and see if we can find this num. bool identify(int num, Node** table){ int key = abs(num%TABLE_SIZE); // search num in table[key]; Node* node = table[key]; while(node!=NULL){ if(node->number == num){ return true; } node = node->next; } // if not found, return false; return false; } // add num into the hash table void add(int num, Node** table){ int key = abs(num%TABLE_SIZE); Node* node = new Node; // insert num and index into table[key] // if this is the first node if(table[key]==NULL){ node->number = num; node->next = NULL; table[key] = node; }else{ // if this is not the first node node->number = num; node->next = table[key]; table[key] = node; } } int replace(int n){ int digit; int result=0; while(n>0){ digit = (n%10); result += digit * digit; n = n/10; } return result; } bool isHappy(int n) { int newN = n; Node* hash_table[TABLE_SIZE]; for(int i=0;i