### Hashing - How to find collision rate?

Guys, I'm having issues calculating the collision rate of this table. It's currently printing out values same as the number of elements inserted. Any ideas?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` ``````#include #include #include "Question_3.hpp" #include int collision = 0; int hash(int num) { int key; key = num % 10; return key; } list::list() { first = last = cur = prev = NULL; } void list::insert(long long int a) { //No collision occurance if (first = NULL) { first = new Node; first->data = a; first->next = NULL; last = first; } else { Node* newNode = new Node; newNode->data = a; newNode-> next = NULL; last = first; collision++; } } void list::display() { cur = first; while (cur != NULL) { cout << " " << cur -> data << " "; cur = cur-> next; } cout << endl; } int main() { int numInserted; int hashvalue; list table[10]; cout << "Please enter 10 elements after each element\n"; for (int i = 0; i < 20; i++) { cout << "Element " << i + 1 << " -> "; numInserted = rand()%10; cout << numInserted << endl; //cin >> numInserted; table[hash(numInserted)].insert(numInserted); } system("pause"); cout << endl; for (int k = 0; k<10; k++) { cout << "Bucket [" << k << "]"; table[k].display(); } cout << "Collsion rate: " << collision << endl; return 0;``````
Line 22 should be using ==, not =.
Thanks. That solved the problem :)
Topic archived. No new replies allowed.