Hashing (Direct Hashing)

Note:

This code was written during a crunch period and isn't perfect. There will be some errant spacing, some files will be using namespace std, etc. But it's all still usable and can be a handy guideline if you're learning Data Structures.

#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>

struct HashTable
{
    HashTable(int size)
    {
        table = std::vector<int>(size, -1);
    }

    void insert(int value)
    {
        int key = value % table.size();
        table[key] = value;
    }

    std::vector<int> table;
};

int main(int argc, char *argv[])
{
    HashTable tb(10);
    for (int x : nums)
        tb.insert(x);
    for (int x : tb.table)
        std::cout << x << " ";
    return 0;
}