Question: LINKED LISTS LINKED LISTS Write a C program using linked lists to read words from stdin, store them in a sorted linked list, and print

LINKED LISTS

LINKED LISTS LINKED LISTS Write a C program using linked lists to

LINKED LISTS

Write a C program using linked lists to read words from stdin, store them in a sorted linked list, and print them in order, along with the frequency of each word. Use the following struct for a node:

typedef struct words{

char word[100];

int freq;

struct words *next;

}Words;

Your program must include the following functions:

Words *addWord(Words *head, char* newWord); Inserts a copy of newWord into the list, in lexicographical order. If newWord is already in the list, increment the freq member of the node. Hint: use strcmp() to compare strings (from string.h). Returns pointer to head of list.

void printWords(Words *head) prints the words in the list, along with the frequency of each word

void deleteList(Words *head) frees the entire list You may assume that words have a fixed maximum size. Your program must free the list before terminating.

Here is some sample output:

$ ./sortWords

cat dog rabbit dog (

cat: 1

dog: 2

rabbit: 1

$

Test your program with insertion in different places in the list, and with update of freq in different places in the list.

Sorted Linked List of Words Write a C program to read words from stdin, store them in a sorted inked list, and print them in order along with the frequency of each word. Use the following struct for a node: typedef struct words char word I100]; int freq; struct words *next; Words; Your program must include the following funct ions: . Words *addWord (Words *head, char* newWord); Inserts a copy of newWord into the list, in lexicographical order. If newWord is already in the list, increment the freq member of the node. Hint: use strpC) to compare strings (from string.h) Returns pointer to head of list. . void printWords (Words *head) prints the words in the list, along with the frequency of each word . void deleteList (Words head) frees the entire list You may assume that words have a fixed maximum size. Your program must free the list before terminating Here is some sample output: (user input in italics, terminated with ctrl-D) $ ./sortWords cat dog rabbit dog cat: 1 dog: 2 rabbit: 1 Test your program with insertion in different places in the list, and with update of freq in different places in the list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!