Thread: Hi needing help
View Single Post
Old 11-18-2005, 09:43 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
I know this answer isn't in strict Java, it's in pseudo C++, but that dosnt matter, its the theory in it that counts.

I would've made the linked list of some class of some sort ie:
Code:
class my_item{
  int count;
  string name;
  my_item * next;
  my_item *prev;
  public: my_item(string  n){name=n; count=1;};
  public: void increment(){count++;};
};
Then when I read a word from the input, see if it's in the list, if it is increment the counter at the appropriate point, else add it to the list.
Once done reading, just sort the linked list according to counter size.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote