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!