Question

Objective:
The purpose of this assignment is to learn and use dynamic data structures. You can use a linked list or tree structure to sort and store a list of symbols (or characters) from a text file according to its ASCII code, and count the number of repetitions of each symbol.

Description:
Given an arbitrary text file, your program will count the number of symbols in the file and print out each symbol and its number of repetitions in the file in ASCII code order. This has to be done using a dynamic data structure. You can use a linked list structure, or a tree structure. Here I only describe the linked list implementation. A linked list structure is simpler to implement, but more time consuming than a tree structure algorithmically.

Instructions:

Here are some basic components for your program design.

1. Your program should ask the text file name, then open the text file successfully for reading. This is done in main.c;
2. You should have a function called “add_item” that will add an item into your linked list according to its alphabetic order or ASCII code order. In other words, the linked list is always sorted according to the alphabetic order. The data structure should also store the number of repetition of each ASCII code. If it is a repetition, you only increase the counter in the corresponding node for the item instead of creating a new node. This should be done in list.c;
3. You should have a function called “print_items” that will print out the characters and the corresponding repetition numbers. This should be done in list.c;
4. “print_items” should return the total number of items printed, which is the number of different ASCII codes counted;
5. In the main program, you should read a character and add_item until the end of the file, print_items, report total number of items, close the file opened, free up the structure that you allocated memory in add_item.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdlib.h>
#include <stdio.h>
#include "list.h"


void add_item(char item) //Add item to linked list
{
    struct Node *temp = head, *temp2; //Temp Nodes for storing data and iterating through list
    if(temp == NULL) //If head is null
    {
   head = (struct Node*)malloc(sizeof(struct Node)); //Create new node
   head->item = item; //Add data to head node
   head->count = 1;
   head->next = NULL;
   return;
    }
    else if(item == head->item) //If item sent in is the same as stored in head
    {
   head->count++; //increment head count
   return;
    }
    else if(item < head->item) //If item sent in comes alphabetically before the current head
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Programming Questions
Homework Solution
$20.00
Programming
C++
Computer Science
Integers
Series
Savings Accounts
Balance
Loops
Statements
Variables
Interest Rates
Deposits
Withdrawals
Input
Output
Malloc
Homework Solution
$8.00
Malloc
Computer
Science
C-Family
Programming
Implementation
Procedures
Memory
Pointer
List
Call
Codes in Matlab and C Programming Language
Homework Solution
$20.00
Computer Science
Mathematics
Programming
Codes
Matlab
C Programming Language
Variables
Statements
Loops
Jobs
Tasks
Input
Output
LCM
Matrices
Arrays
Pointers
Conversions
Grader in C++
Homework Solution
$20.00
Average
Score
Input
Output
C++
Student
Grades
Computer
Science
Programming
Arithmetic
Mean
Get help from a qualified tutor
Live Chats