Question

Using C code 1. Consider a hash table that is implemented using the following struct definitions....

Using C code

1. Consider a hash table that is implemented using the following struct definitions.

#define NUMBUCKETS 10

typedef struct _HTE {
    int Key;
    int Value;
    struct _HTE *Next;
} HashTableEntry;

typedef struct _HT {
    HashTableEntry *Buckets[ NUMBUCKETS ];
    unsigned int Size;
} HashTable;

a.) Complete the following function, which takes a pointer to a HashTableEntry, which is the head of a linked list of entries, and an integer x. It returns the first entry in the list whose value is greater than x or NULL if the list doesn’t have such an entry. Be sure to declare and initialize any local variables. Using the following implementation:

HashTableEntry* Get_First_Larger(HashTableEntry* head, int x) {

....

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#define NUMBUCKETS 10

typedef struct _HTE {
    int Key;
    int Value;
    struct _HTE *Next;
} HashTableEntry;

typedef struct _HT {
    HashTableEntry *Buckets[ NUMBUCKETS ];
    unsigned int Size;
} HashTable;

HashTableEntry* Get_First_Larger(HashTableEntry* head, int x) {
   while(head != NULL){
       if(head->Value > x) return head;
       head = head->Next;
   }
   return NULL;
}

Add a comment
Know the answer?
Add Answer to:
Using C code 1. Consider a hash table that is implemented using the following struct definitions....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function...

    Follow the TODOs and complete the insertItem(), searchItem() and printTable() functions in hash.cpp. The hash function has already been implemented for you. // hash.CPP program to implement hashing with chaining #include<iostream> #include "hash.hpp" using namespace std; node* HashTable::createNode(int key, node* next) { node* nw = new node; nw->key = key; nw->next = next; return nw; } HashTable::HashTable(int bsize) { this->tableSize= bsize; table = new node*[tableSize]; for(int i=0;i<bsize;i++) table[i] = nullptr; } //function to calculate hash function unsigned int HashTable::hashFunction(int key)...

  • Insert elements into a hash table implemented using chain hashing, as an array of linked list...

    Insert elements into a hash table implemented using chain hashing, as an array of linked list in which each entry slot is as a linked list of key/value pairings that have the same hash (outcome value computed using certain hash function). You are allowed to use “Hash Function”, h(k) = k % x where, x is the value you will need to decide to use, that you find appropriate for this implementation. The main requirements are the following: 1. Input:...

  • Hashtable in C Please fix void ht_put(hashtable_t *ht, char *key, void *val) and void free_hashtable(hashtable_t *ht)...

    Hashtable in C Please fix void ht_put(hashtable_t *ht, char *key, void *val) and void free_hashtable(hashtable_t *ht) Implement void ht_del(hashtable_t *ht, char *key) and void ht_rehash(hashtable_t *ht, unsigned long newsize) --------------[hashtable.h]--------------------------------------- -######################################### #ifndef HASHTABLE_T #define HASHTABLE_T typedef struct hashtable hashtable_t; typedef struct bucket bucket_t; struct bucket { char *key; void *val; bucket_t *next; }; struct hashtable { unsigned long size; bucket_t **buckets; }; unsigned long hash(char *str); hashtable_t *make_hashtable(unsigned long size); void ht_put(hashtable_t *ht, char *key, void *val); void *ht_get(hashtable_t *ht,...

  • Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly...

    Please answer this problem in C++, Thank you! Read and study the sample program: "hashing with chaining using singly linked lists", as well as "hashing with chaining using doubly linked lists". Notice this program is complete except it doesn't include the remove function. Write the remove function and test it with the rest of the program including the given main program. Upload your C++ source file. ---Here is the referenced program: "hashing with chaining using singly linked lists". Below this...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • A linked list of integers is built using the following struct: struct node {   int data;...

    A linked list of integers is built using the following struct: struct node {   int data;   struct node *next; }; Define a function named max that returns the maximum integer in a list. The function takes one arguments, a pointer to the head of the list. The function returns an integer, which is the maximum value. If the list is empty, return zero. NOTE: You know nothing about the values in the list. They could all be negative!

  • Currently I am learning about set theory. I am trying to implement a set using a hashtable with singly linked lists. I a...

    Currently I am learning about set theory. I am trying to implement a set using a hashtable with singly linked lists. I am very confused as to where I should start, as many of the online resources reference basically hash table implementations. How would I go about a template to implement the very basic structures needed for the set in C? Just confused as to where to start. Currently this is my current structure: typedef struct s_entry t char *key...

  • Please Write the following code in C: PRELAB - Week of October 14 For this prelab...

    Please Write the following code in C: PRELAB - Week of October 14 For this prelab you will implement the following functions: List * initIntegerList() // Return empty list int insertAtHead(int k, List*) // Insert k at head int insertAtTail(int k, List*) // Insert k at tail int removeHead(List *) // Remove head and return its key int getListSize(List *) // Return number of elements in list void printHead(List *) // Print key in head void moveHeadToTail(List *) // Move...

  • C++ Consider the following structure of node and linked list. struct Node { int key; Node...

    C++ Consider the following structure of node and linked list. struct Node { int key; Node *next; }; 10 -> 20 -> 30 -> 10 -> 10 -> 50 -> 10 -> NULL What will be the output of following pseudo-code? Consider head is the pointer to the first node of above linked list. Node *walker = head; int count = 0; while(walker!= NULL && count < 3) { if(walker->key == 10) { count = count + 1; } walker...

  • Codelab question! This is c++. Consider the following code: // Linked Lists: TRAVERSE struct ListNode {...

    Codelab question! This is c++. Consider the following code: // Linked Lists: TRAVERSE struct ListNode { int data; struct ListNode *next; }; Assume that a linked list has been created and head points to a sentinel node. A sentinel node is an empty data node in the beginning of the list. It sometimes holds a sentinel value. The use of sentinel nodes is a popular trick to simplify the insert and delete operations. You may also assume that the list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT