Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 04-03-2005, 04:24 PM   #1
Member (7 bit)
 
shaticus's Avatar
 
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
shaticus is offline   Reply With Quote
Old 04-04-2005, 08:21 AM   #2
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Quote:
keeps track of the number of times a word is used in a linked list. But, the linked list has to be alphabetized.
Why would you alphabetize the same word? Maybe I am reading it incorrectly, but what exactly are you alphabetizing?
faulkner132 is offline   Reply With Quote
Old 04-04-2005, 01:28 PM   #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.
alfie2 is offline   Reply With Quote
Old 04-04-2005, 01:56 PM   #4
Member (7 bit)
 
shaticus's Avatar
 
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.
shaticus is offline   Reply With Quote
Old 04-04-2005, 04:25 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).
alfie2 is offline   Reply With Quote
Old 04-04-2005, 06:25 PM   #6
Member (7 bit)
 
shaticus's Avatar
 
Join Date: May 2004
Posts: 103
Thanks, Ill give that a try
shaticus is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:20 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2