When i compile the code i get a error 'No match for operator !=' (operand type are 'int' and 'std::vector::iterator' on line 8 But when i use the same operator on line 41 there seems to be no problem
#include<iostream>
#include<vector>
using namespace std;
vector<int> Heap;
int Size;
auto k =0;
void max_heapify(vector<int> vect)
{
int vect_size= vect.size()/2;
for(k=vect_size; k != vect.end();k--)//line 8
{
if(vect[(2*k)+1]>vect[k])
{
vect[k]=vect[2*k]+1;
}
else if(vect[2*k]+2>vect[k])
{
vect[k]=vect[2*k]+2;
}
}
}
int main()
{
int items;
cout<<"Enter the size of the heap"<<endl;
cin>>Size;
cout<<"Enter the first element(root) and then the left and the right elements accordingly"<<endl;
for(int i=1;i<=Size;i++)
{
cout<<"Enter the"<<" "<<i<<" "<<"element";
cin>>items;
Heap.push_back(items);
}
for(auto j=Heap.begin();j!=Heap.end();j++)
{
cout<<*j<<endl;
}
max_heapify(Heap);
for(auto j=Heap.begin();j!=Heap.end();j++)//line 41
{
cout<<*j<<endl;
}
}
Aucun commentaire:
Enregistrer un commentaire