I want to insert a node int the end of the linked list, but I don't know how to achieve.
#include <stdio.h>
#include <stdlib.h>
typedef struct Info* PtrToNode;
struct Info {
int number;
PtrToNode next;
};
typedef struct Info* list;
typedef struct HashNode* HashTable;
struct HashNode {
list Heads;
int size;
};
HashTable createTable(int size) {
HashTable H = (HashTable)malloc(sizeof(struct HashNode));
H->size = size;
H->Heads = (PtrToNode)malloc(H->size * sizeof(struct Info));
for (int i = 0; i < H->size; ++i)
{
H->Heads[i].number = 0;
H->Heads[i].next = NULL;
}
return H;
}
int Hash(int n, int size) {
return n % size;
}
void insert(HashTable H, int index, int number) {
int pos = Hash(number, H->size);
list check = H->Heads[pos].next;
while (check) {
check = check->next;
}
PtrToNode newNode = (PtrToNode)malloc(sizeof(struct Info));
newNode->number = number;
newNode->next = NULL;
check = newNode;
}
I want append in the insert function, but the params "check" like temporary, and if I "while" the H->heads[pos], the node always in the head.