0
이 삽입 기능이 올바르게 삽입되지 않은 것으로 보이고 이전 항목을 덮어 씁니다. 또한 중복 검사는 의도 한대로 작동하지 않으며 반 시간에만 작동합니다.해시 테이블 :이 코드가 충돌을 해결하지 못하는 이유는 무엇입니까?
HT::HT(const unsigned& tblSize) {
//Hash table size equal to size passed or default size TBL_SIZE
hsize = tblSize;
//Pointer table defualt 0
psize = 0;
//reisze tables
hTable.resize(hsize);
pTable.resize(hsize);
//set unused values to empty($$$)
for(unsigned i = 0; i < hsize; i++)
hTable[i].key = FREE;
}
//implementation of insert function
void HT::insert(const Entry& record) {
//assign integer value to index via hash function
int index = (hash(record.key) % 31);
//logic to insert into hash table
for(unsigned i = 0; i < hsize; i++) {
//inserting into table with linear probing collision resolution
//inserting into hash table with linear probing as collision resolution
if (hTable[(index+i)%hsize].key == FREE) {
hTable[index] = record;
pTable[psize] = &hTable[(index+i)%hsize];
psize++;
cout << " Entry = " << ((index+i)%hsize) << endl;
return;
}
//Duplicate key check
else if (hTable[(index+i)%hsize].key == record.key) {
cout << " Entry = Not Inserted - Duplicate key!! " << endl; return;
}
//Capacity of table check
else if (i == hsize - 1) {
cout << " Not Inserted - Table full!! " << endl; return;
}
} //end for loop
}
잘 삽입하는 것와 중복 키 검사는 $$도 = 31 무료 상수 세트 모든 벡터 값을 TBL_SIZE하는 테이블을 채우기 더 많은 데이터 값과 다른 하나의 데이터 세트에서 작동하지만 무료 자리를 지정하려면 $.
멋진 캐치입니다! – lpapp