Monday, May 24, 2010

What do these do in c++?

char* tokenWords[55];


vector%26lt;string%26gt; table;


int j = 0; int k = 0;


string word; // One word per string





for(i = 0; i %26lt; 54; i++)


{


table.push_back(string(tokenWords[i]))...


}


--------------------------------------...


in tokenWords we have word.


and


----


for(j = 0; j %26lt; 54; j++)


for(i = 0; i %26lt; table.size() - 1; i++)


{


if(table[i] == table[i+1])


{


table.erase(table.begin() + i + 1);


}


}


esp the vector function.

What do these do in c++?
It looks like this code is making a list of all the words that were originally in tokenWords. It does this by putting all the words into a vector, and running through it 54 times, each time comparing every set of two words, and deleting the second one from the table vector if they are the same. After that function completes, "table" will contain a list of all words in tokenWords, in the order in which they occurred, with no duplicates.





P.S. This is not very efficient code.
Reply:It's code about a table class in a bunch of for loops...





j can't get bigger than 54, and i ends up building to that size...





meh I don't know what the code is for, drawing a table? lol


No comments:

Post a Comment