Confusion in chaining

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.
well your list implementation would contain an array of elements (probably dynamic array) like std::vector.

regardless of how elements are sorted or not sorted you access them with head pointers which you store inside the elements.

you should write and show some minimal code for start.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace 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?
Last edited on
@jonnin @lastchance
Guys! Am I doing it right?
lost110 wrote:
Guys! Am I doing it right?


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.
Topic archived. No new replies allowed.