help with creating a hash table

This is a discussion on help with creating a hash table within the C++ Programming forums, part of the General Programming Boards category; I'm writing a program that find solutions to the 8-puzzle game I need to make a hash table that has ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    2

    help with creating a hash table

    I'm writing a program that find solutions to the 8-puzzle game

    I need to make a hash table that has 2 operations

    member(node *) which takes a pointer to a node and determines if the board in the node is equal

    // member method to see if a value is in the table
    // I'm not sure how to adapy this code
    int hashtable::HLookup(int value){

    // get the index
    int index = hash(value);

    // get the location in the table
    node *p = table[index];

    // p is the head of a linked list, so now we need to
    //scan the link list to find the value
    int found = 0;

    while(p != NULL)
    {
    countHash++;
    // see if the current element matches
    if(p->value == value)
    {
    found = true;
    break;
    }

    // go to next element
    else p = p->next;
    }

    return found;

    }


    insert (node *) which puts a new node in the hash table

    // insert method
    //not sure how to use a pointer here
    void hashtable::HInsert (int value){
    node *p = table [hash(value)];

    if (p==NULL){
    countHash++;
    table [hash(value)] = new node;
    table [hash (value)]->value = value;
    }

    else {
    while (p->next !=NULL){
    p = p->next;
    countHash++;
    }
    p->next = new node;
    }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    How much of the hash table have you implemented? Are you having trouble with some part of it or just getting started? Try searching the boards, I've posted two full implementations of a hash table, one very recently that may help.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    2
    how do i find your hash implementations?

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    2nd entry on search for hash table with author prelude revealed this.

    http://64.191.71.186/cboard/showthre...highlight=hash
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dictionary in C# to hash table in C?
    By dinoman in forum C Programming
    Replies: 2
    Last Post: 04-12-2009, 09:23 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  4. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  5. Hash table creation and insertion
    By tgshah in forum C Programming
    Replies: 1
    Last Post: 01-23-2006, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21