I am using a constructor to initialize the instance variable. When I print the instance variable it gives wrong output.
int main(){
int k[]={1,2,4};
int hs=3;
int n=3;
priorityq p(k,hs,n);
p.printKey();
}
class priorityq{
int key[];
int heapsize;
int n;
public:
void printKey();
priorityq(int k[],int hs, int ni);
};
priorityq::priorityq(int k[],int hs, int ni){
for(int i=0;i<ni;i++)
key[i]=k[i];
heapsize=hs;
n=n_i;
}
void priorityq::printKey(){
for(int i=0;i<heap_size;i++)
cout<<key[i]<<" ";
cout<<endl;
}
I expect output to be 1 2 4 but am getting 3 3 4