Here you are (note the hash function, and hence the output, it is slightly different)
#include<stdio.h>
#include <stdlib.h>
#include <assert.h>
#define SIZE 10
typedef struct Node
{
unsigned data;
struct Node * next;
} Node;
void list_cleanup(Node *pHead )
{
while ( pHead )
{
Node * pNext = pHead->next;
free( pHead );
pHead = pNext;
}
}
Node * list_insert(Node * pHead, int data )
{
Node * pNewNode = (malloc(sizeof (Node)));
assert(pNewNode);
pNewNode->data = data;
if ( ! pHead || pNewNode->data < pHead->data )
{
pNewNode->next = pHead;
return pNewNode;
}
Node * pCurNode = pHead;
while ( pCurNode->next && pCurNode->next->data < pNewNode->data )
{
pCurNode = pCurNode->next;
}
pNewNode->next = pCurNode->next;
pCurNode->next = pNewNode;
return pHead;
}
unsigned hash_function(int n, int max)
{
unsigned address = (n * SIZE)/(max+1);
return address;
}
void address_calculation_sort( unsigned arr[], unsigned ArrSize)
{
assert(arr);
if ( ArrSize < 1) return;
Node * pHead[SIZE];
unsigned n;
for (n=0; n<SIZE; ++n)
pHead[n] = NULL;
int max = arr[0];
for (n=1; n < ArrSize; ++n)
if ( max < arr[n])
max = arr[n];
for (n=0; n<ArrSize; ++n)
{
unsigned v = arr[n];
unsigned address = hash_function(v, max);
pHead[address] = list_insert(pHead[address], v);
}
for (n=0; n<SIZE; ++n)
{
printf("ADDRESS %u: ", n );
Node *pCurNode = pHead[n];
while ( pCurNode )
{
printf("%u ", pCurNode->data);
pCurNode = pCurNode->next;
}
printf("\n");
}
unsigned index = 0;
for (n=0; n<SIZE; ++n)
{
Node *pCurNode = pHead[n];
while ( pCurNode )
{
arr[index++] = pCurNode->data;
pCurNode = pCurNode->next;
}
}
for (n=0; n<SIZE; ++n)
list_cleanup(pHead[n]);
}
int main()
{
unsigned arr [] = { 29, 23, 14, 5, 15, 10, 3, 18, 1 };
const unsigned ArrSize = sizeof(arr)/sizeof(arr[0]);
unsigned n;
printf("Input array: ");
for (n=0; n<ArrSize; ++n)
printf("%u ",arr[n]);
printf("\n");
address_calculation_sort(arr, ArrSize);
printf("Sorted array: ");
for (n=0; n<ArrSize; ++n)
printf("%u ",arr[n]);
printf("\n");
return 0;
}
Output:
Input array: 29 23 14 5 15 10 3 18 1
ADDRESS 0: 1
ADDRESS 1: 3 5
ADDRESS 2:
ADDRESS 3: 10
ADDRESS 4: 14
ADDRESS 5: 15
ADDRESS 6: 18
ADDRESS 7: 23
ADDRESS 8:
ADDRESS 9: 29
Sorted array: 1 3 5 10 14 15 18 23 29