Please convert to C language //linear probing #include using namespace std; void add_using_linear_probing(int hash[], int a) { //hash function h(x)=x%10 int k = a % 10; //linear probing while (true)...


Please convert to
C language



//linear probing
#include
using namespace std;


void add_using_linear_probing(int hash[], int a)
{
    //hash function h(x)=x%10
    int k = a % 10;


    //linear probing
    while (true) {
        if (hash[k] == -1) {
            hash[k] = a;
            break;
        }
        k = (k + 1) % 10; //linear increment of probe
    }
}


int main()
{
    //set of input numbers
    vector arr{ 123, 124, 333, 4679, 983 };


    //initialize the hash table
    //each entry of the hash table is a single entry
    int hash[10]; //size of hashtable is 10
    memset(hash, -1, sizeof(hash)); //initialize with empty initially


    for (int a : arr) {
        //hashing
        add_using_linear_probing(hash, a);
    }


    cout < "---------using="" linear="">


    cout < "hash="" table="">


    for (int i = 0; i < 10;="" i++)="">
        if (hash[i] == -1)
            cout < i="">< "-="">"
 < "empty"=""><>
        else
            cout < i="">< "-="">" < hash[i]=""><>
    }


    return 0;
}




Output:


----using linear probing--<br>Hash table is:<br>0->Empty<br>1->Empty<br>2->Empty<br>3->123<br>4->124<br>5->333<br>6->983<br>7->Empty<br>8->Empty<br>9->4679<br>

Extracted text: ----using linear probing-- Hash table is: 0->Empty 1->Empty 2->Empty 3->123 4->124 5->333 6->983 7->Empty 8->Empty 9->4679

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here