The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 305 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Need help debugging code (C++). Getting errors "C3861'Hash': identifier not found" and "C2660 'Index_Finder': function does not take 5 arguments".
Please Comment where error was fixed.
Attached code
#include<iostream>
#include <cstdlib>
using namespace std;
bool Linear_Probing(int array[], bool flags[], int MAX_SIZE, int number, int & collisions);
int Index_Finder(int number, bool flags[], int MAX_SIZE, int &collisions);
bool Linear_Probing(int array[], bool flags[], int MAX_SIZE, int number, int &collisions)
{
   int dummy_collisions = 0;
   int index = Index_Finder(number, flags, MAX_SIZE, dummy_collisions);
   if (index == -1)
      return false;
   else
   {
      collisions += dummy_collisions;
      array[index] = number;
      flags[index] = true;
      return true;
   }
}
int Index_Finder(int number, bool flags[], int MAX_SIZE, int &collisions)
{
   int index = Hash(number);
   if (index < MAX_SIZE && !flags[index])
      return index;
   if (index >= MAX_SIZE)
   {
      index = 0;
      if (!flags[index])
         return index;
      else
         collisions++;
   }
   else
   {
      collisions++;
   }
   int limit = index;
   return Index_Finder(flags, MAX_SIZE, ++index, limit, collisions);
}
int Index_Finder(bool flags[], int MAX_SIZE, int index, int limit, int &collisions)
{
   if (limit == index)
      return -1;
   if (index == MAX_SIZE)
      index = 0;
   if (!flags[index])
      return index;
   else
   {
      collisions++;
      return Index_Finder(flags, MAX_SIZE, ++index, limit, collisions);
   }
}
int Hash(int number)
{
   int first_digit = 0, last_digit = 0;
   bool first_time = true;
   while (number > 0)
   {
      if (first_time)
      {
         first_digit = number % 10;
         number -= (number % 10);
         number /= 10;
         first_time = false;
      }
      else
      {
         last_digit = number % 10;
         number -= (number % 10);
         number /= 10;
      }
   }
   return (first_digit + last_digit);
}
int main() {
   const int MAX_SIZE = 11;
   int collisions = 0;
   int array[MAX_SIZE];
   bool flags[MAX_SIZE];
   for (int i = 0; i < MAX_SIZE; i++) {
      array[i] = 0;
      flags[i] = false;
   }
   Linear_Probing(array, flags, MAX_SIZE, 67, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 19, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 3, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 808, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 337, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 1, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 86, collisions);
   Linear_Probing(array, flags, MAX_SIZE, 38, collisions);
   return 0;
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly