|
Prev: Generate UUID that fits on 37 digits [0-9]
Next: discount , adidas,nba ( paypal accept ) ( www.power-saler.cn )discount , adidas,nba ( paypal accept ) ( www.power-saler.cn )
From: arnuld on 6 May 2008 06:36 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: 1) Create a singly-linked list and store each word and the count in that structure. when the user enters a word which is already seen before, then we will just increase the count. That way we will have a list of unique words. 2.) Create an array of pointers to the elements of linked list (which are structure actually). Sort the pointers comparing the count of each word and print the elements pointed by these pointers. That way program will be highly efficient as we will not be sorting any structures, we will be sorting pointers only :) . (originally K&R2's idea but I love this idea) I want this program to be fast and consume less memory. I have 2 questions: i.) a double-linked list will be better than this ? ii.) any other data structure that I can use here ? -- http://lispmachine.wordpress.com/ my email ID is @ the above blog. just check the "About Myself" page :) |