Purchase Solution

Linked List that Counts Unique Entries

Not what you're looking for?

Ask Custom Question

See the attached file.

We have a list of numbers and we need to know two things, what numbers we have and how many of each number do we have in the list.
So we read in each number and add the number to an ordered linked list. If we are adding a number to the list and we find that number, then we will just count it. If we do not find the number in the linked list, then we will add a new node to the linked list with the new number and set the count to one.

The linked list node will have three fields - the number, a counter for the number and a link field.

Write a C++ program to achieve what we want, and print out the values and their counts, say 5 per line.

Example:
5(22) 8(15) 13(5) 22(3) 25(18)
where 5 is the number and 22 is its count.

Please use the attached input file "LinkNbrs.dat" for testing the program.

Attachments
Purchase this Solution

Solution Summary

This solution creates a C++ Linked List program to know unique numbers and their counts in a list of numbers.

Solution Preview

Please see the attachment as well. Program code here may look different than actual code because of html treatment of this content.

// 438155.cpp

#include <iostream>
#include <fstream>
using namespace std;

typedef struct NodeType {
int value;
int counter;
struct NodeType *next;
} Node;

class LinkedList {
private:
Node *root;
public:
LinkedList() {
root = NULL;
}
void display();
void add(int num);
};

void LinkedList::display() ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.