a sort problem!!!

I have this basic code setup up and two functions set up shown below (word.h and word.cpp). I need write a simple class to represent the string of sorted letters, including a method to sort the letters of a string into alphabetical order.I then need to write some output code to output all the entries of the anagram array to standard output, putting the anagram and all of the words which are anagrams on the same line, like this:

elmno lemon melon

The output produced by your code at the end of exercise 1 will be an unsorted anagram dictionary. Clearly, you could sort this output using the sort program

#include <iostream>
#include <string>
#include "word.h"
#include <stdlib.h>

using namespace std;

int main() {

const int Dictionary_Length = 46000;

Word Dictionary[Dictionary_Length]; // Dictionary array.

int L; // This is used to index the first *unused* element of the dictionary array.

// Read in the dictionary from standard input. A blank line terminates the input file.

string Temp;
for (L = 0; L < Dictionary_Length; L++) {
getline(cin, Temp);
if (Temp.length() == 0) break;
Dictionary[L].Setword(Temp);

}

if (L == Dictionary_Length) {
cout << "Error : input file exceeds storage!" << endl;
exit(EXIT_FAILURE);
}

for (int i = L - 1; i >= 0; i--) cout << Dictionary[i].Getword() << endl;

exit(EXIT_SUCCESS);
}

word.h=
#ifndef WORD_H
#define WORD_H

#include <string>

using std::string;

class Word{

public:
void Setword (string);
string Getword();

private:
string Actual;
};

#endif

word.cpp=
#include <stdlib.h>

#include "word.h"

#include <iostream>
using namespace std;

void Word::Setword (string t) {
Actual = t;
}

string Word::Getword(){
return Actual;
}

I can use either a heap or bubble sort but think the heap will be more efficient, so any help coming up with a sort wud be great! Another function will also probably have to be created but i've just about ran out of ideas and really struggling to find a solution.
Well, what you could do is go through the word and count how many of each letter is in it, then try to find words with the same amount of letters.
Topic archived. No new replies allowed.