Help with hashing

Having trouble generating a hash function for my code below.

How would I use the numbers on a telephone? For example, each letter
has a number associated with it.

Trying to generate 512 random 3 letter initials and take statistics on
a linked list array size 512 to hold this information.

Also, how would I go about reporting how many have no elements, 1 element,
2 elements, etc...? How can I figure out the maximum number of collisions? Should both results agree with the hashing statistics distribution?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h> 
using namespace std; 
  
void printInitials(const string& name) 
{ 
    if (name.length() == 0) 
        return; 
  
    // Since touuper() returns int, we do typecasting 
    cout << (char)toupper(name[0]); 
  
    // Traverse rest of the string and print the 
    // characters after spaces. 
    for (int i = 1; i < name.length() - 1; i++) 
        if (name[i] == ' ') 
            cout << " " << (char)toupper(name[i + 1]); 
} 
  
// Driver code 
int main() 
{ 
    string name = "prabhat kumar singh"; 
    printInitials(name); 
    return 0; 
} 
How would I use the numbers on a telephone? For example, each letter
has a number associated with it.

need more words on what that means.



Trying to generate 512 random 3 letter initials
the phone does not use all the letters. Do you want 3 letters from what a phone has, or something else?
either way, load a string with the letters you can use and randomly pick one 3 times per go. Use the length of the string to set up the random function. Look at <random> example code in any <random> documentation online to see how to do that.


Start there. See if you can generate the data, then we can look at the 2nd half.


Topic archived. No new replies allowed.