Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:39:17+00:00 2026-06-04T23:39:17+00:00

How do I make a hash table representation using an array in C++ for

  • 0

How do I make a hash table representation using an array in C++ for a table and apply a hash function such as k % 10 to it? I’m to use chaining to resolve collision (i.e. the table is an array of linked lists).

I am to also insert, search, and delete values into/from this table.

So far, I have:

struct Node {
    int value;
    Node* next;
}; 

void insert(int n, Node* hashtable[]) {

    int x = n % 10;
... ...

Say for example for the value 10, my hash function would produce 0, so 10 goes into the first slot of the array/hash table.

Then if I had the value 100, 100 would also go to the first slot, so my 10 would “point” to 100… how would I code this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:39:18+00:00Added an answer on June 4, 2026 at 11:39 pm

    something like

    Node* oldFront = hashtable[hashcode];
    Node* newNode = new Node(value, oldFront);
    hashtable[hashcode] = newNode;
    

    This will add the most recent collision to the front of the linked list, i.e. it operates as a stack. Adding it to the back is left as an exercise for the questioner!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little context: I'm trying to make a very simple hashing function/hash table as
I'm trying to make a script to use multiple values in window.location.hash but i'm
I have to write my own hash function. If I wanted to just make
Is it possible using a certain hash function and method (the division method, or
I'm currently implementing a hash table in C++ and I'm trying to make a
Just trying to make a kind of hash table with each node being a
I evaluated the following elisp code in ielm: (setq foo-hash (make-hash-table)) (puthash location house
I am doing a md5 hash, and just want to make sure the result
Make it on Linux. The reason to use more than one version of Vim,
I'm trying to implement some data structures (like HAMP-hash array mapped trie) in Common

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.