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

  • Thread starter Thread starter brad sue
  • Start date Start date
  • Tags Tags
    List
Click For Summary
SUMMARY

This discussion focuses on sorting words from a file using a linked list while skipping punctuation such as commas, exclamation marks, and periods. The user seeks an algorithm to achieve this, and several methods are proposed, including reading into a linked list and sorting, using a bucket approach, or employing a tree structure for sorting. The suggested format for reading words while excluding punctuation is "%[^,!.]s". Each method offers a different approach to efficiently manage and sort the input data.

PREREQUISITES
  • Understanding of linked lists in programming
  • Familiarity with file input/output operations
  • Knowledge of string manipulation techniques
  • Basic sorting algorithms and data structures
NEXT STEPS
  • Implement a linked list sorting algorithm in C or C++
  • Explore bucket sort and its implementation for string data
  • Learn about tree data structures and their sorting capabilities
  • Investigate regular expressions for advanced string parsing
USEFUL FOR

Programmers, computer science students, and software developers interested in data structures, string manipulation, and sorting algorithms.

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:

Similar threads

Replies
35
Views
8K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
15
Views
3K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
1
Views
3K
Replies
4
Views
4K