Re: Linked List confusion
- From: "[Jongware]" <sorry@xxxxxxxxxxx>
- Date: Tue, 06 May 2008 15:32:58 +0200
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]
.
- Follow-Ups:
- Re: Linked List confusion
- From: arnuld
- Re: Linked List confusion
- References:
- Linked List confusion
- From: arnuld
- Re: Linked List confusion
- From: Ben Bacarisse
- Linked List confusion
- Prev by Date: Re: Linked List confusion
- Next by Date: Re: Linked List confusion
- Previous by thread: Re: Linked List confusion
- Next by thread: Re: Linked List confusion
- Index(es):
Relevant Pages
|