Re: Linked List confusion




Ben Bacarisse wrote:
arnuld <sunrise@xxxxxxxxxxxxxxxx> writes:

PROBLEM:

I want to read words from standard input and then sort and print
the words in decreasing order of appearance along with the count of how many times each word occurred. The language I am using C. I
have come up with following design idea:

[...]
ii.) any other data structure that I can use here ?

Binary search trees and hash tables are the most obvious choices. For
simplicity, you could try to keep a sorted array of string pointers.
This will speed up the accesses when a word is read and will give you
a simple way to print the words at the end.

I wrote exactly that same program, using only a binary tree. Printing the words was done with a recursive routine -- which is also a pretty simple way :-)
Despite heavy use of generalized C functions such as strdup, strcmp, etc., its performance was astounding; a matter of seconds, and most of this time was input/output. My test file was an ASCII version of the King James Bible, so now I know how often people used to say "thee" in those times.

[Jongware]
.



Relevant Pages

  • Linked List confusion
    ... I want to read words from standard input and then sort and print ... the words in decreasing order of appearance along with the count ... Create an array of pointers to the elements of linked list ...
    (comp.programming)
  • Re: Linked List confusion
    ... I want to read words from standard input and then sort and print ... the words in decreasing order of appearance along with the count ...
    (comp.programming)
  • Re: Thanks Joel for informing the FDA about LYMErix
    ... Loon...got news for you...that sort of public comment session is ... usually reserved for the appearance of public input. ...
    (sci.med.diseases.lyme)
  • Re: .Net 1.1 component creates bad directory entry
    ... you could write an app to scan the desktop for the ... appearance of the install window and send it the appropriate events. ... Sort ...
    (microsoft.public.windowsxp.embedded)
  • Re: Irishism or not?
    ... M16. ... L16. ... Of fine, impressive, or stately appearance; ... It refers to a sort of beauty that goes with strength and character, ...
    (soc.culture.irish)