I was implementing some data structures for fun in C, and I was comparing the speed to other data structures I implemented. This one is a closed addressing hash table.
This is the code I used to create a node
hashNode *createNewNode(int data) {
hashNode *node = calloc(1, sizeof(hashNode));
node->data.key = data;
node->isSet = true;
node->next = NULL;
}
This is the function I wanted to time.
for (int i = 0; i < 5; i++) {
hashNode *node = createNewNode(arr[i]);
InsertNode(node, map);
}
(arr is just the first 5000 numbers shuffled)
As you may have noticed the function to create a node doesn’t have a return value, still despite this the node is initialized correctly and all the numbers that were supposed to be in the table were inserted, and only those. How could that happen?
This gimmik only works in VS Code, I tried running it in Visual Studio but it (correctly) doesn’t initialize the node. Does anyone know what is happening?
NoobProgrammer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.