Implement hash_table.c and linked_list.c and main.c with provided hash_table.h, linked_list.h. find anagrams using hasht

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Implement hash_table.c and linked_list.c and main.c with provided hash_table.h, linked_list.h. find anagrams using hasht

Post by answerhappygod »

Implement hash_table.c andlinked_list.c and main.c withprovided hash_table.h, linked_list.h.
find anagrams using hashtables.
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 1
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 1 (22.53 KiB) Viewed 25 times
Let say word.txt is
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 2
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 2 (2.96 KiB) Viewed 25 times
Implement main.c
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 3
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 3 (71.93 KiB) Viewed 25 times
Implement linked_list.c
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 4
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 4 (403.33 KiB) Viewed 25 times
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 5
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 5 (145.19 KiB) Viewed 25 times
Implement hast_table.c
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 6
Implement Hash Table C And Linked List C And Main C With Provided Hash Table H Linked List H Find Anagrams Using Hasht 6 (403.33 KiB) Viewed 25 times
Create a program to print out anagrams using the following steps: For each word in the file, sort the characters of the word. (any sort will work) Use the sorted characters as a key in the hashtable, where the value is the list of words in the file composed of those letters. Implement a function to return the list of anagrams of a given word. (this can be as simple as a printout to sysout) For example, given the dictionary [cog, dog, cat, tacl, goc=> [cog] and act => [cat, tac] First, your program must work and print out a list of all the anagrams. Apart from that, you have lots of decisions to make!
raver ravers ravery raves ravigote ravigotes ravin ravinate ravine ravined ravinement
#include<stdio.h> #include<stdlib.h> #include<string.h> const int MAP_SIZE = 100; typedef struct AnagramValue { char* key; char** anagrams; AnagramValue* next; } typedef struct AnagramMap { AnagramValue* data; } typedef struct SortedAnagram { char* sortedWord; char* originalWord; } SortedAnagram** sortWords (char** words) { } int hash (char* str) { } int length = strlen(str); return length * (length + 3) % MAP_SIZE; AnagramMap* buildAnagramMap (SortedAnagram** anagrams) { } char** findAnagrams (char* toFind) { } int main() { //step 1 - read in the list and store it into a buffer (a buffer is just an array) //step 2 - sort the words to find the keys. } //2.a - you could build your map as you sort //2.b - you could use a struct to associate your sorted key with the word //my structure above implies option 2 //step3 - iterate through your array of SortedAnagram and add each value to your map //step4 - hash `toFind to get the index for the word you're looking for //step5 - iterate through your collection of AnagramValue to find the equivalent key
#ifndef LINKEDLIST_H #define LINKEDLIST_H typedef struct l1_node { char *payload; struct ll_node *next; struct ll_node *prev; } LinkedListNode, *LinkedListNodePtr; typedef struct ll_head { uint64_t Linked ListNodePtr head; LinkedListNodePtr tail; } LinkedListHead; num_elements; typedef struct ll_iter { LinkedList } LLIterSt; list; Linked ListNodePtr cur_node; typedef struct ll_head *LinkedList; struct ll_iter; typedef struct ll_iter *LLIter; // Creates a LinkedListNode by malloc'ing the space. // INPUT: A pointer that the payload of the returned LLNode will point to. // Returns a pointer to the new LinkedListNode. LinkedListNode* CreateLinkedListNode (char *data); // Destroys and free's a provided LLNode. // INPUT: A pointer to the node to destroy. // Returns 0 if the destroy was successful. int DestroyLinked ListNode (Linked ListNode *node); // Removes a given element from a linkedList. // INPUT: A pointer to a linked list. and A ListNodePtr that points to a LLNode to be removed from the list. // Returns 0 if the destroy was successful int RemoveLLElem (LinkedList list, LinkedListNodePtr ptr); // A Doubly-Linked List // Creates a LinkedList. // The customer is responsible for calling DestroyLinked List () // to destroy and free the LinkedList when done. // Returns a LinkedList; NULL if there's an error. LinkedList CreateLinkedList(); // Destroys a LinkedList. // All structs associated with a LinkedList will be // released and freed. Payload_free_function will // be used to free the payloads in the list. // INPUT: A pointer to a LinkedList. // INPUT: A pointer to a function used to free the payload. // Returns 0 if the destroy was successful; non-zero for failure. int DestroyLinked List (LinkedList list); // Returns the number of elements in the linked list. // INPUT: A LinkedList // Returns the number of elements in the list. unsigned int NumElementsInLinkedList (LinkedList list); // Adds an element to the head of a LinkedList, with the string // as the given pointer. // The customer is responsible for allocating the string. // INPUT: A pointer to the LinkedList that will be added to, // INPUT: A pointer to a string for a node in the linkedList. // // Returns 0 if the insertion was successful; non-zero for failure. int InsertLinked List (LinkedList, char*); // Copies the pointer to the payload at the head of a list // to the provided dataPtr, and removes the head node from the list. // INPUT: A pointer to the LinkedList. // INPUT: A pointer to a char* that will be updated // with the char* at the head of the list. // Returns 0 if the pop was successful; non-zero for failure. int PopLinkedList (LinkedList list, char** dataPtr); // Sorts the list given the comparator. Any sort works // INPUT: The list to sort // INPUT: 1 if the sort should be ascending; for descending. void SortLinked List (LinkedList list, unsigned int ascending);
// LLIter: A Linked List Iterator // Creates a iterator for the given linked List. // It is the customer's responsibility to ensure // that the iterator is destroyed before modifying // the LinkedList. // The customer also needs to call DestroyLLIter to free // it when the customer is done. // INPUT: A pointer to a LinkedList to be iterated. LLIter CreateLLIter (LinkedList list); // Determines if there are more elements in a given iterator. // INPUT: An existing iterator. // Returns 0 if there are no next elements; 1 if there are. int LLIterHasNext (LLIter iter); // Determines if there are more elements in a given iterator. // INPUT: An existing iterator. // Returns 0 if there are no previous elements; 1 if there are. int LLIterHasPrev (LLIter iter); // Steps the iterator to the next element in the LinkedList. // INPUT: A pointer to an existing iterators. // Returns 0 if it was successful. int LLIterNext (LLIter iter); // Steps the iterator to the previous element in the LinkedList // if there is one. // INPUT: A pointer to an existing iterators. // Returns if successful; 1 otherwise. int LLIterPrev (LLIter iter); // Destroys and frees the given iterator. // INPUT: A 0 to an existing iterator. // Returns 0 if the iterator was successfully // destroyed and freed. int DestroyLLIter (LLIter iter); // Copies the pointer to the payload of the current element // to the pointer specified by the argument. // INPUT: The iterator // INPUT: A pointer to a place to copy the payload pointer. // Returns 0 if successful; 1 otherwise. int LLIterGetPayload (LLIter iter, char** payload); // Delete the node the iterator is pointing to. After deletion, the iterator is either: // - invalid and cannot be used (but must be freed), if there was only one element in the list // - pointing to the successor of the deleted node, if there is one. // - pointing to the predecessor of the deleted node, if the iterator was pointing at // the tail before LLIterDelete was called. // INPUT: the iterator to delete from // INPUT: function invoked to free the payload // // Returns: // - 1 if the deletion succeeded, but the list is now empty // -0 if the deletion succeeded, and the list is still non-empty int LLIterDelete (LLIter iter); // Insert an element right before the node that the interator points // to. (If you want to insert at the end of a list, use // AppendLinkedList.) // // INPUT: the iterator to insert through // INPUT: the payload to insert // // Returns: // 1 on failure (out of memory) // 0 on success; the iterator still points to the same node, // not to the inserted node. int LLIterInsertBefore(LLIter iter, char* payload); #endif // LINKEDLIST_HL
#ifndef LINKEDLIST_H #define LINKEDLIST_H typedef struct l1_node { char *payload; struct ll_node *next; struct ll_node *prev; } LinkedListNode, *LinkedListNodePtr; typedef struct ll_head { uint64_t Linked ListNodePtr head; LinkedListNodePtr tail; } LinkedListHead; num_elements; typedef struct ll_iter { LinkedList } LLIterSt; list; Linked ListNodePtr cur_node; typedef struct ll_head *LinkedList; struct ll_iter; typedef struct ll_iter *LLIter; // Creates a LinkedListNode by malloc'ing the space. // INPUT: A pointer that the payload of the returned LLNode will point to. // Returns a pointer to the new LinkedListNode. LinkedListNode* CreateLinkedListNode (char *data); // Destroys and free's a provided LLNode. // INPUT: A pointer to the node to destroy. // Returns 0 if the destroy was successful. int DestroyLinked ListNode (Linked ListNode *node); // Removes a given element from a linkedList. // INPUT: A pointer to a linked list. and A ListNodePtr that points to a LLNode to be removed from the list. // Returns 0 if the destroy was successful int RemoveLLElem (LinkedList list, LinkedListNodePtr ptr); // A Doubly-Linked List // Creates a LinkedList. // The customer is responsible for calling DestroyLinked List () // to destroy and free the LinkedList when done. // Returns a LinkedList; NULL if there's an error. LinkedList CreateLinkedList(); // Destroys a LinkedList. // All structs associated with a LinkedList will be // released and freed. Payload_free_function will // be used to free the payloads in the list. // INPUT: A pointer to a LinkedList. // INPUT: A pointer to a function used to free the payload. // Returns 0 if the destroy was successful; non-zero for failure. int DestroyLinked List (LinkedList list); // Returns the number of elements in the linked list. // INPUT: A LinkedList // Returns the number of elements in the list. unsigned int NumElementsInLinkedList (LinkedList list); // Adds an element to the head of a LinkedList, with the string // as the given pointer. // The customer is responsible for allocating the string. // INPUT: A pointer to the LinkedList that will be added to, // INPUT: A pointer to a string for a node in the linkedList. // // Returns 0 if the insertion was successful; non-zero for failure. int InsertLinked List (LinkedList, char*); // Copies the pointer to the payload at the head of a list // to the provided dataPtr, and removes the head node from the list. // INPUT: A pointer to the LinkedList. // INPUT: A pointer to a char* that will be updated // with the char* at the head of the list. // Returns 0 if the pop was successful; non-zero for failure. int PopLinkedList (LinkedList list, char** dataPtr); // Sorts the list given the comparator. Any sort works // INPUT: The list to sort // INPUT: 1 if the sort should be ascending; for descending. void SortLinked List (LinkedList list, unsigned int ascending);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply