Share
Explore BrainMass

# Linked List that Counts Unique Entries

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.

#### 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;

private:
Node *root;
public:
root = NULL;
}
void display();
};

#### Solution Summary

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

\$2.19