469,300 Members | 2,311 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,300 developers. It's quick & easy.

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 2214
Banfa
9,064 Expert Mod 8TB
Your idea sounds about right to be.
Sep 8 '06 #2

Post your reply

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

Similar topics

8 posts views Thread by Steven | last post: by
7 posts views Thread by eric.gagnon | last post: by
3 posts views Thread by Jim Carlock | last post: by
19 posts views Thread by pkirk25 | last post: by
1 post views Thread by archanapatelwhite | last post: by
7 posts views Thread by Adrian | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.