Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In addition to my comment above, which led you to find one of the bugs you have, I will add this:</p> <p>The reason why you crash is that your <code>Hash</code> class mismanages the hash table. First of all, you allocate an array of 100 <code>HashEntry</code> pointers:</p> <pre><code>HashEntry *Table[100]; </code></pre> <p>Notice that you never set those pointers to anything - so they're pointing to who knows what. Perhaps they will, by sheer luck, point to NULL, but the chances of that are miniscule - you're way way way more likely to win the lottery. So, you are accessing some random memory - and that's <strong>bad</strong>.</p> <p>The solution to that is to set each entry to <code>NULL</code> explicitly using a loop in your constructor. You will also need a destructor to free any allocated entries, so that you can <code>delete</code> it and not leak memory, because leaking is bad.</p> <p>But an interesting question is why do it like that at all? Why not simply declare the buckets like this:</p> <pre><code>HashEntry Table[100]; </code></pre> <p>That way all your buckets are allocated as part of the <code>Hash</code> object and you don't have to worry about dynamically allocating and deallocating buckets, checking pointers for <code>NULL</code> etc.</p> <p>One problem with doing that is that your <code>HashEntry</code> constructor requires an <code>int</code> argument. It's unclear why that argument is necessary; I don't think that you need it and and you could just remove it. </p> <p>This <em>one</em> change would have simplified your code dramatically and eliminated three bugs and the crash.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload