I have to read all the data(integers) from file into the array and then iterate the array to make minimum heap and adding them after the last element of the current heap. After reading into array I have to call SiftUp()
. on each element.At the end of all the inputs I am trying to print out the first five elements of the min heap array. output gives me the following error.
Error occurs:
[Error] invalid conversion from 'int' to 'int*' [-fpermissive]
my program:
using namespace std;
int heapSize;
void SiftUp(int arr[], int heapSize);
const int arr_Size=500;
int heapArr[arr_Size];
int main()
{
int integers;
string fileName;
ifstream infile;
cout << "Please enter the name of the file to open :";
cin >> fileName;
infile.open(fileName.c_str());
if(!infile)
{
cerr << "An eror occurred while openieng the file.";
exit(1);
}
while(!infile.eof())
{
for (int i=0; i<arr_Size; i++)
{
infile >> integers;
heapArr[i]=integers;
heapSize=i;
cout << "numbers " << heapArr[i] << endl;
SiftUp(heapArr[i],heapSize); // Error: invalid conversion
}
}
infile.close();
return 0;
}
void SiftUp(int arr[], int heapSize)
{
int p;
if (heapSize==1)
return;
else p = heapSize/2;
if (arr[p] > arr[heapSize])
return;
else swap (arr[heapSize],arr[p]);
SiftUp(arr[], p); // Error : expected primary-expression before ']'
for (int count =0 ; count <5 ; count ++)
{
cout << " at index 1 : " << arr[count] << endl;
}
}
int i;
for (i=1; i<arr_Size; i++){
infile >> integer;
if(infile.fail())break;
heapArr[i]=integer;
SiftUp(i);
}
infile.close();
heapSize=i;
for (int count =1 ; count <=5 ; count ++){
cout << count <<" :"<< heapArr[count] << endl;
}
return 0;
}
void SiftUp(int heapSize){
int p;
if (heapSize==1) return;
p = heapSize/2;
if (heapArr[p] < heapArr[heapSize]) return;
swap (heapArr[heapSize],heapArr[p]);
SiftUp(p);
}