In this assignment you will create a linked list in the HEAP and implement algorithms for manipulating it. Each node of the linked list contains a key/value pair and a pointer to the next node, where "key" is a string and "value" is an integer. Your program should have the following functions: 1- create_dummy: Allocate
Explanation / Answer
#include typedef char * string; //The linked list struct Node { string Data; struct Node *Next; }*Head; // Adding a Node at the Beginning of the List void addBeg(char word[]) { struct Node *temp; temp=(struct Node *)malloc(sizeof(struct Node)); temp->Data = word; if (Head == NULL) { //List is Empty Head=temp; Head->Next=NULL; } else { temp->Next=Head; Head=temp; } } // Counts the number of elements in the list int length() { struct Node *cur_ptr; int count=0; cur_ptr=Head; while(cur_ptr != NULL) { cur_ptr=cur_ptr->Next; count++; } return(count); } // Displays the contents of a list void display() { struct Node *cur_ptr; cur_ptr=Head; if(cur_ptr==NULL) { printf(" List is Empty"); } else { printf("Elements in the List: "); //traverse the entire linked list while(cur_ptr!=NULL) { printf(" -> %s ",cur_ptr->Data); cur_ptr=cur_ptr->Next; } printf(" Frequency: %d ",length()); printf(" "); } } //The hash table struct Node* hash[500]; //The key fucntion turns each letter of a given word into its corresponding ASCII //value and then adds these values together. void key(char word[]) { int i, numLetter; int numWord = 0; //numWord is the value of the key after the hash function is performed for(i = 0; i