So what I have understood so far is that we have to make an array of head pointers which will be pointing to separate linked lists. So this is what we would call the implementation of chaining through an array or linked list? I have been given a task to implement chaining, linear probing etc through an array.
#include <iostream>
usingnamespace std;
struct node
{
node *next;
int data;
};
void input(int x)
{
int count = 0;
node *newnode = new node;
cout << "Enter data of node :" << endl;
cin >> newnode->data;
if (newnode->data > x) // if data is greater than size of array
{
newnode->data = hashfun(newnode->data); // send the data to hash function
while (count != newnode->data); // now compare data with indexes
{
count++;
}
}
}
int hashfun(int y)
{
int m = y % 10;
return m;
}
int main()
{
int x;
cout << "Enter size of array:" << endl;
cin >> x;
node *head=new node[x];
cout << "Enter how much data you want to enter" << endl;
for (int i = 0; i < x; i++)
{
input(x);
}
}
This is just raw code! How would I point the head pointer to its first chain node?
I haven't a clue what you are trying to do! So, I've no idea.
It is unclear whether you are trying to build a linked list of not. If there is some other thread that you are referring to then maybe it would have been better to continue on that thread rather than presume our understanding of what your obscure original post here is talking about.