Vgwizardx 0 Newbie Poster

This is my first group project me and one other person wrote the majority of this program. I put message on the functions and other things i need help on. It seems to work a little bit but I'm not getting the correct values when I try to run this in a small list with no collisions. I'm trying to do a hashing project using separate chaining. Any advice on what you see here will help thanks.

#include <iostream>
#include <cstdlib>
using namespace std;

//What I need help on!!!
// global structure definition
typedef struct node {
  int data;
  struct node *next;
};

//What I need help on!!!!
node* Initialize()
{
  node *currentNode = new (nothrow) node;

  if (currentNode == NULL) {
     cout << "Heap error - could not allocate memory" << endl;
  }
  else
  {
     // initialize to empty list
     currentNode->data = 0;
     currentNode->next = NULL;
  }

  return currentNode;
}

//What I need help on!!!!
void InitializeArray(node *chainingArr[], int hashTableSize)
{
    node *currentNode;

    for (int i = 0; i < hashTableSize; i++)
    {
        currentNode = Initialize();
        chainingArr[i] = currentNode;
    }

}

//What I need help on!!!!
void resolveWithSeparateChaining (node *chainingArr[], int randomNum, int addr)
{
    node *newNode = chainingArr[addr];

    newNode = new (nothrow) node;
    
    cout << newNode->data << endl;
    newNode->data = randomNum;
    newNode->next = NULL;

    if(chainingArr[addr] == NULL)
       chainingArr[addr] = newNode;
    else
    {
        newNode->next = chainingArr[addr];
        chainingArr[addr] = newNode;
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.