0
How to put a dictionary in C++, and more?
-including swapping adjacent characters in a word, -inserting a single character in between two adjacent characters in a word, -deleting a single character from a word, and -replacing a character in a word with another character
8 Respuestas
+ 1
Object called Word, that has an internal private data structure that is a String, representing a word.
Then public methods that do what you want to the word, declared something like this:
bool swapAdjacentCharacters(int letterIndex)
bool insertCharacterBetweenAdjacentCharacter(int letterIndex, char characterToInsert)
Does that give you enough to get on with?
+ 1
Thank you, would it make a difference if I use void instead of bool?
+ 1
I'd do
#include <array>
array<string, 10> HashTable;
Try to avoid handcrafted data structures and raw pointers.
+ 1
And don't use namespace std in a header file because you force everybody who includes it to use it, too.
0
void is fine. Bool was just so if the function failed, it could return false.
This is to improve error checking. Example, if word is a single character "a" or "I", functions will fail. If index specified is bigger than the word length,.etc. You should probably capture errors.
0
Should I use a data type char, or string when I'm declaring a variable to represent words?
0
String, as there are more things you can do to a string, and it's less prone to pointer problems.
0
This is my header file so far:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#ifndef SPELL_H
#define SPELL_H
class spellchecker {
private:
static const int tableSize = 10;
struct item {
string W;
item* next;
};
item*HashTable[tableSize];
public:
spellchecker();
int Spellchecks(string s);
bool Insert(string W);
bool swapAdjChar();
void SpellCheck();
void Remove();
};
#endif /*SPELL_H*/