Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void createDataStructures(vector<string> &originalWords, vector< vector<string> > &chains,
- vector< vector<string> > &endings, const int CHAIN_SIZE)
- {
- for (int i = 0; i<(int)(originalWords.size())-CHAIN_SIZE; i++)
- {
- //create vectors to insert into chains and endings
- vector<string> lhs;
- vector<string> rhs;
- int n;
- for (n=0; n<CHAIN_SIZE; n++)
- {
- string temp = originalWords[i+n];
- lhs.push_back(temp);
- }
- string rhString = ((i+n) < (int)(originalWords.size())) ? originalWords[i+n] : END;
- bool inserted = false;
- //now that we have the lhs and rhs variables, add them to the parrallel vectors.
- for (int i = 0; i<(int)(chains.size()); i++) //scan chains for vector to insert
- {
- if (chains[i] == lhs) //lhs vector already exists in chains
- {
- endings.at(i).push_back(rhString);
- inserted = true;
- }
- }
- //lhs vector does not exist in chains
- if (!inserted)
- {
- chains.push_back(lhs);
- endings.push_back(rhs);
- }
- }
- }
Add Comment
Please, Sign In to add comment