I have this program which is an implementation of a heap and the error LNK2019 occurs
//What should i do???????
Code:
#include <iostream>
using namespace std;
class Heap {
public:
int treeData[1000]; // a heap of up to 999 elements. position 0 is kept for size
void heap();
void add(int);
};
void Heap::heap() {
treeData[0] = 0; //set the size to 0
}
void Heap::add(int v) {
treeData[0]++; //increase the size
int pos = treeData[0];
treeData[pos] = v; //put the value in the next position in the complete tree
while(pos >1) { //as long as the root is not reached
if(treeData[pos] > treeData[pos/2]) {//if value of node is bigger than the parent
int tmp = treeData[pos];
treeData[pos] = treeData[pos/2];
treeData[pos/2] = tmp; //swap the value of the child with the parent
pos = pos/2; //update the position to the parent
}
else return; //else stop
}
}
void Heap::remove(){
int size= treeData[0];
treeData[1]=treeData[size];
treeData[size]= 0;
treeData[0] --;
for (int i=1; i<(treeData[0]/2)+1;i++){
if (treeData[i]<treeData[i*2]){
int tmp =treeData[i];
treeData[i]=treeData[i*2];
treeData[i*2]=tmp;
}
if(treeData[i]<treeData[(i*2)+1]){
int tmp=treeData[i];
treeData[i]=treeData[(i*2)+1];
treeData[(i*2)+1]=tmp;
}
}
}
void Heap::showroot() {
int root;
root=treeData[1];
cout << root <<endl;
}
void main() {
Heap myheap;
myheap.add(35);
myheap.add(68);
myheap.add(76);
myheap.add(22);
myheap.add(9);
myheap.add(83);
myheap.add(12);
myheap.add(2);
myheap.add(43);
cout << myheap.treeData[0];
for (int i=myheap.treeData[0]; i !=0, --i;) {
cout << num++ <<": ";
myheap.showroot();
myheap.remove();
}
}
Comment