Sorting Words w/ Linked List & Skipping Punctuation - Help Needed

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    List
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
brad sue
Messages
270
Reaction score
0
Hi,
I have two problems:
please can someone give me an algorithm that would help me to understand how to put words ( read from a file) in alphabetical order using a linked list. I just don't get it!

Also, The words that I need to input is a real text.
but There is punctuation (",", "!",".") that I need to skip in order to continue inputting words.
I know that I can do
Code:
 fscanf(fptr,"  [^,], ", words)
to skip the comma. but how can I do all the 3 punctuations in once?

Thank you for your help
B.
 
Physics news on Phys.org
1) There are a lot of ways you can do this.

a) You can read everything into a linked list and then sort
b) You can use a bucket approach. Stick words in an appropriate bucket based on the first letter of the word, then sort each bucket and combine.
c) You can use a tree approach. Same as bucket approach, but you can have a linked list of sub-buckets. You'll be sorting on the fly with this method. All you have to do at the end is combine.

Which one do you want to do?

2) Isn't it just:

"%[^,!.]s"

You're modifing the string to exlude ',', '!', and '.'
 
Last edited: