473,432 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Storing many strings, print alphabetical, print # of duplicates.

Hi,

I am after some advice about which data structures I should use. I'm developing a program and I am at the point where all the strings are being generated and printed one by one with loops/recursion using printf("%s\n", my_string);. Instead of printing them, I need to sort them in alphabetical order, and record the amount of times a unique string appears.

i.e it will print

"ABCD 4" because ABCD appeared 4 times.
"BCC 1" because BCC comes after ABCD in alphabetical order and appears once.

My idea is to incorporate a binary (search?) tree, adding the strings one by one, and then printing the tree using inorder traversal. How would I integrate the duplicate string counter though? I then thought perhaps insert each item into the tree as a structure containing an int and a string, and everytime I insert a string, I should check for duplicates, and if found, update that int in the appropriate node's structure. I'm not sure if this is all that efficient. I have a feeling there's an easier and more efficient way, but I can't think of anything better.

Any input/advice/suggestions from anybody is greatly appreciated.

Thanks!
Sep 8 '06 #1
1 2462
Banfa
9,065 Expert Mod 8TB
Your idea sounds about right to be.
Sep 8 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Steven | last post by:
Hi there, I am wanting to store price data as n.nn format, so if the user enters "1" the data that gets stored is "1.00" Is there a way to do this. Cheers Steven
7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
3
by: Jim Carlock | last post by:
I'm creating a lot of arrays. Some of the arrays carry words that get duplicated... For example: $aCities = {"Durham", "Raleigh", "Raleigh-Durham", "Salem", "Winston", "Winston-Salem" } I've...
19
by: pkirk25 | last post by:
I wonder if anyone has time to write a small example program based on this data or to critique my own effort? A file called Realm List.html contains the following data: Bladefist-Horde...
1
by: archanapatelwhite | last post by:
Hi below is the code I am using. ------------------------------------ SET NOCOUNT ON DECLARE @emailid varchar(50), @rastype varchar(50), @message varchar(80) declare @allrastypes...
7
by: Adrian | last post by:
Hi, I want a const static std::set of strings which is case insensitive for the values. So I have the following which seems to work but something doesnt seem right about it. Is there a better...
7
by: canteyn | last post by:
Here is my problem: Structure typedef struct { char lname; char fname; int age; double salary; } employee_t;
9
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.