-
Linked list
Im trying to make a program in c++ that will take some files, grab each word individualy, get rid of any doubles, sort the words from a-z and write each word to the console. I have no idea how to go about doing this. Would linked list's do this? Im asking because i would have to learn them, and i dont want to learn them yet if there not gonna help.
-
Linked list are optional, I'd suggest other datastructures for faster sorting but they are more complicated, but in actuallity very easy to understand.
How many words to sort (about) and would you like it to go as fast as possible?
-
Thats just it. It could be 2 words, or it could be 50,000. I heard linked list can grow as needed, thats why they came to mind first.
-
C++ supports dynamic arrays in that you can expand the array any time you need.
Linked lists are structs that point forward and backward to the next/previous struct. It's like a list of records that know their immediate nextdoor neighbors, but nobody else.
Code:
struct LL {
struct LL *backward;
char data[20];
struct LL *forward
};
What you want is an array. Since I just posted the algorithm for removing duplicates, I gonna be lazy and tell you to go here:
IT's for an array of chars, but the logic is the same - compare with strcmp() which returns 0 if the two are equal.
http://www.vbforums.com./showthread....hreadid=107643
-
That'd be arrays of C-strings then. Quicksort, Shellsort, Mergesort, Bucketsort, Heapsort, Radixsort, what would you like?