Nel link che ho postato ci sono le Struct necessiare
https://onlinegdb.com/QR3W9nCz_
In allegato ci sono anche gli errori
![Immagine](https://i.imgur.com/x6awUV0l.png)
![Immagine](https://i.imgur.com/oaxRCBsl.png)
void HTtoArray_range(THT* ht, TArray* array, TKey min, TKey max) {
TList list = listCreate();
TInfo imin = {min}, imax = {max};
for (int i = 0; i < ht->n_bucket; i++)
for (TNode *node = ht->bucket[i]; node != NULL; node = node->link)
if (!infoLess(node->info, imin) && !infoGreater(node->info, imax))
arraySet(ht, array->info.key, array->info.value);
ht = HTdelete(ht, ht->info);
}
for (int i = 0; i < ht->n_bucket; i++)
{
for (TNode *node = ht->bucket[i]; node != NULL; node = node->link)
{
if (node->info.key >= min && node->info.key <= max)
{
arrayAdd(array, node->info);
}
}
}
>
e <
se i limiti vanno esclusi. Poi basta che iteri sull'array ed elimini dentro la hash table usando le key.void
HTtoArray_range2(THT *ht, TArray *array, TKey min, TKey max)
{
for( TKey key = min; key <= max; key++ )
{
TValue* value = HTsearch (ht, min);
if( value )
{
TInfo info;
info.key = key;
info.value = *value;
arrayAdd(array, info);
HTdelete(ht, key);
}
}
}
void printOrderedArray_exemptions(TArray* array) {
int i;
TList list_ord = listCreate();
for(i=0; i<array->length; i++){
list_ord = listInsert(list_ord, array->items[i]);
}
}
apatriarca ha scritto:Quali difficoltà incontri nella comprensione dei concetti? Forse ti possiamo aiutare.
TBST BSTtoHT_exemption(TBST bst, THT* ht) {
if (bst != NULL) {
bst->left = BSTtoHT_exemption(bst->left, ht);
bst->right = BSTtoHT_exemption(bst->right, ht);
if ((bst->info.key%2) == 0) {
HTinsert(ht, bst->info.key, bst->info.value);
bst = BSTdelete(bst, bst->info);
}
}
return bst;
}
Visitano il forum: Nessuno e 1 ospite