|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
#1 |
|
Member (7 bit)
Join Date: May 2004
Posts: 103
|
C++ string functions
I have to write a program for my comp sci class that reads text in from a file and keeps track of the number of times a word is used in a linked list. But, the linked list has to be alphabetized.
How do you alphabetize some thing like this? Is there any library to do this? Thanks, shaticus |
|
|
|
|
|
#2 | |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
Quote:
|
|
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
I think "shaticus" mean a "sorted linked list" of words in a text file.
each node as: { Word:text Num :integer next ointer} The trick here is the insertion part which should do the parsing/sorting of the list as well. ps, I cant do your homework for you, but can give you some pointers(get it?) hahaha. sorry cant resist. |
|
|
|
|
|
#4 |
|
Member (7 bit)
Join Date: May 2004
Posts: 103
|
LOL
Just need some info on how to alphabetize the list. Is there a way to compare the letters or could I just assume the ascii value would be in the right order so that it would sort right. Will this work or is there a better approach to it? Thanks Edit: Not asking for you to do the homework, just asking for some help about this one portion. I already have everything else working, just not sure how to tell the computer to alphabetize something. Last edited by shaticus; 04-04-2005 at 02:00 PM. |
|
|
|
|
|
#5 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
Basicaly, there is a "strcmp" function in "string.h" which
"int strcmp ( const char * string1, const char * string2 )" return value description <0 : string1 is less than string2 0 : string1 is the same as string2 >0 : string1 is greater than string2 In your case, for example: previous pointer = current pointer if list empty then create list move current pointer else { FOUND = (strcmp(previous_string,current_string)); while not FOUND and not end of list { move previous node pointer( previous = current) move current node pointer along;( current = next) } if ( FOUND = 0) then (current.word_count++) //**** found same word else insert new node before "current" node.( previous) } then your list would be in ascending order or (alphabetize). |
|
|
|
|
|
#6 |
|
Member (7 bit)
Join Date: May 2004
Posts: 103
|
Thanks, Ill give that a try
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|