구조체 힙의 소멸자에 문제가 있습니다. 하나만 추가하고 사용하지 않을 경우 런타임 예외 (메모리 액세스)가 생성됩니다. 두 번째 날에하려고하고 내일은 마감일입니다.소멸자 정의를 추가하면 실행중인 예외가 발생합니다.
struct Heap
{
int n;
int* tab;
int* numerWKopcu;
Heap() { n=0; }
Heap (int size) { this->tab = new int[liczbaDomow]; n=0; this->numerWKopcu = new int[2000100];}
int max() { return tab[1]; }
bool empty() { return n==0; }
bool insert(int x)
{
n++;
tab[n]=x;
this->numerWKopcu[x] = n;//ZMIANA
upHeap(n);
return true;
}
bool delMin()
{
if (n<1) return false;
this->numerWKopcu[tab[n]] = 1; //ZMIANA
tab[1]=tab[n]; n--;
downHeap(1);
return true;
}
void upHeap(int x){
int p;
int mem = tab[x];
while (x>1)
{
p=x/2;
if (color[mem]>color[tab[p]]) break;
this->numerWKopcu[tab[p]] = x; //ZMIANA
tab[x]=tab[p];
x=p;
}
this->numerWKopcu[mem] = x;//ZMIANA
tab[x]=mem;
}
void downHeap (int x)
{
int s=2*x;
int mem=tab[x];
while(s<=n)
{
if (s+1<=n && color[tab[s]]>color[tab[s+1]])
s++;
if (color[mem]>color[tab[s]])
{
this->numerWKopcu[tab[s]] = x; //ZMIANA
tab[x]=tab[s];
x=s;
s=2*x;
}
else break;
}
this->numerWKopcu[mem] = x;//ZMIANA
tab[x]=mem;
}
void write()
{
for (int i=1;i<=n;i++) printf ("%d) %d\n", i, tab[i]);
printf ("\n");
}
void build()
{
int s = n;
for (s=n/2; s>=1; s--) downHeap(s);
}
/~Heap() {
delete []this->numerWKopcu;
delete []this-> tab;
};
};
정확한 오류 메시지를 게시하십시오 ... – Nick
이 코드는 불완전하며 (예 :'liczbaDomow'는 정의되지 않았습니다) 영어 이외의 변수 이름을 사용합니다. 두 가지 모두 함께 사람들이 당신을 도울 수 없게 만듭니다. – thiton
디버거에서 실행 해 보았습니까? –