15,849,996 members
See more:
```# Python3 code for implementation of
# Address Calculation Sorting using Hashing

# Size of the address table (In this case 0-9)

SIZE = 10

class Node(object):

def __init__(self, data = None):

self.data = data

self.nextNode = None

def __init__(self):

# Insert values in such a way that the list remains sorted

def insert(self, data):

newNode = Node(data)

# If there is no node or new Node's value

# is smaller than the first value in the list,

# Insert new Node in the first place

else:

# If the next node is null or its value

# is greater than the new Node's value,

# Insert new Node in that place

while current.nextNode != None \

and \

current.nextNode.data < data:

current = current.nextNode

newNode.nextNode = current.nextNode

current.nextNode = newNode

# This function sorts the given list
# using Address Calculation Sorting using Hashing

# Declare a list of Linked Lists of given SIZE

for i in range(SIZE):

# Calculate maximum value in the array

maximum = max(arr)

# Find the address of each value

# and insert it in that list

for val in arr:

# after all the values have been inserted

for i in range(SIZE):

print("ADDRESS " + str(i), end = ": ")

while current != None:

print(current.data, end = " ")

current = current.nextNode

print()

# Assign the sorted values to the input array

index = 0

for i in range(SIZE):

while current != None:

arr[index] = current.data

index += 1

current = current.nextNode

# This function returns the corresponding address
# of given value in the address table

def hashFunction(num, maximum):

# Scale the value such that address is between 0 to 9

address = int((num * 1.0 / maximum) * (SIZE-1))

# -------------------------------------------------------
# Driver code

# giving the input address as follows

arr = [29, 23, 14, 5, 15, 10, 3, 18, 1]

# Printing the Input array

print("\nInput array: " + " ".join([str(x) for x in arr]))

# printing the result sorted array

print("\nSorted array: " + " ".join([str(x) for x in arr])) ```

What I have tried:

Converting object oriented code to c program is difficult for me
Posted
Updated 10-Jul-21 2:06am
Richard MacCutchan 17-Nov-19 7:05am
Unless you are an experienced C programmer you will need to search Google for a tool to help you.

## Solution 1

Here you are (note the hash function, and hence the output, it is slightly different)
C
```#include<stdio.h>
#include <stdlib.h>
#include <assert.h>
#define SIZE	10

typedef struct Node
{
unsigned data;
struct Node * next;
} Node;

// release memory
{
{
}
}

// insert values in such a way that the list remains sorted
Node * list_insert(Node * pHead, int data )
{
Node * pNewNode = (malloc(sizeof (Node)));
assert(pNewNode);
pNewNode->data = data;

{
return pNewNode;
}

while ( pCurNode->next && pCurNode->next->data < pNewNode->data )
{
pCurNode = pCurNode->next;
}
pNewNode->next = pCurNode->next;
pCurNode->next = pNewNode;
}

// the has function is slightly different
unsigned hash_function(int n, int max)
{
unsigned address =  (n * SIZE)/(max+1);
}

void address_calculation_sort( unsigned  arr[], unsigned  ArrSize)
{
assert(arr);
if ( ArrSize < 1) return;

unsigned n;
for (n=0; n<SIZE; ++n)

// find the maximum of the array values
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];
}

for (n=0; n<SIZE; ++n)
{
while ( pCurNode )
{
printf("%u ", pCurNode->data);
pCurNode = pCurNode->next;
}
printf("\n");
}

unsigned index = 0;
for (n=0; n<SIZE; ++n)
{
while ( pCurNode )
{
arr[index++] = pCurNode->data;
pCurNode = pCurNode->next;
}
}

for (n=0; n<SIZE; ++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");

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