I've been working with something and I'm a little lost..
**the code is in english**, just find and replace jijij
there are 2 functions left: print and check spelling.
it's like a syntax corrector.
you write your word and the program tells you if you got some errors and
tells you what options are correct...
like ms word, but more simple...
this is what i got so far:
the program just add words to the memory... but doesn't print or compare any.
hope you can help me out.
thank you very much for your time.
ps. i will incorporate irrlicht user interface after.
Code: Select all
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class node{
public:
node(char l){
letter=l;
brother = NULL;
upper_left_son=NULL;
father = NULL;
}
char letter;
node *brother;
node *upper_left_son;
node *father;
};//end class - node
class Tree{
public:
void add(string word);
void add(node *,node *,string,int,int);
//void print(); dont know
//void compare(); dont know
private:
node *root;
};
void Tree::add(string word)
{
node *newNode = new node(word[0]);
if(root == NULL)
{
root = newNode;
}
else
{
for(node *tmp = root; tmp != NULL; tmp = tmp->brother)
{
if(tmp->letter==word[0])
{
break;
}
if(tmp->brother == NULL)
{
tmp->brother = newNode;
break;
}
}
}
for(int i = 1; i < word.length(); i++)
{
newNode = new node(word[i]);
add(root,newNode,word,0,i);
}
}
void Tree::add(node *key, node *newNode, string word, int index, int limit)
{
if (index < limit)
{
for(node *temp = key; temp != NULL; temp = temp -> brother )
{
if(temp -> letter == word[index])
{
add(temp->upper_left_son, newNode , word , index + 1 , limit);
if(index == limit-1)
{
if(temp -> upper_left_son == NULL)
{
temp -> upper_left_son = newNode;
}
else
{
for(node *temp2 = temp -> upper_left_son ; temp2 != NULL ; temp2 = temp2 -> brother)
{
if(temp2->letter==word[limit])
{
break;
}
if(temp2->brother == NULL)
{
temp2->brother = newNode;
break;
}
}
}
}
}
}
}
}
int main(){
string word;
Tree *a = new Tree();
//a bunch of words with "a"
a->add("word");a->add("aaronita");a->add("aba");a->add("ababa");a->add("ababillarse");
a->add("ababol");a->add("abacal");a->add("abacalero");a->add("abacero");a->add("abachar");
a->add("abacora");a->add("abad");a->add("abada");a->add("abadiado");a->add("abandonar");
a->add("anabdonismo");a->add("abandonista");a->add("abanear");a->add("abanico");a->add("abanicazo");
a->add("abanico");a->add("abanillo");a->add("abanino");a->add("abarajar");a->add("abarañar");
a->add("abaratamiento");a->add("abaratar");a->add("abarcar");a->add("acarrado");a->add("abarraganimiento");
a->add("abarraganarse");a->add("abarrajado");a->add("abarrotar");a->add("abarrotero");a->add("abastecimiento");
a->add("abcedario");a->add("abedul");a->add("abejonear");a->add("abellota");a->add("abellotado");
cout<<"Syntax reviewer\n"<<endl;
//String word;
cout<<"type a word: ";
cin>>word;
return 0;
}