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

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    List
AI Thread Summary
To sort words from a file in alphabetical order using a linked list, several approaches can be employed. One method involves reading all words into a linked list and then sorting them. Alternatively, a bucket approach can be used, where words are categorized into buckets based on their initial letters, sorted within those buckets, and then combined. A tree approach is another option, allowing for dynamic sorting with linked sub-buckets. For handling punctuation, the suggested format string "%[^,!.]s" can be used to read words while excluding commas, exclamation points, and periods simultaneously.
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.
 
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top