-
what you mean by this ?? ?? :) cheers
as i know that otherset is a StringSet... it can't used of insert
i try this
Code:
StringSet StringSet::set_union(StringSet otherset)
{
StringSet UnionResult;
for(int i = 0; i < contents.size(); i++)
{
UnionResult.insert( contents[i] );
UnionResult.inser( otherset ); // ???????
}
return UnionResult;
}
-
i being thinking .......
insert otherset into contents
and another loop to insert the overall contents into UnionResult....is tat alright?
-
Code:
StringSet StringSet::set_union(StringSet otherset)
{
StringSet UnionResult;
for(int i = contents.size(); i > contents.size(); i++)
{
//UnionResult.insert( contents[i] );
otherset.insert( contents[i] );
}
for(int i = 0; i < contents.size(); i++)
{
UnionResult.insert( contents[i] );
}
return UnionResult;
}
-
More like:
Code:
StringSet StringSet::set_union(const StringSet& otherset) const
{
StringSet result;
// copy over contents of this StringSet
result.contents.assign(contents.begin(), contents.end());
// insert the contents of the other StringSet
for (unsigned int i = 0; i < otherset.contents.size(); ++i)
{
result.insert(otherset.contents[i]);
}
return result;
}
-
is the assign keywords?
new for me .. hehe....can you please explain...? thank you ...
-
I am assuming that the contents member variable is a standard container such as a std::vector. You should read up on what assign() does.
-
ok i understand assign() by viewing www.cppreference.com
really thanx laserlight .. you are brilliant...
one more question which i dont really understand why i could not display wat i want....
this is my class = header file
Code:
#include <string>
#include <iostream>
#include <vector>
#include "stringset.h"
using namespace std;
class InvertedIndex
{
//insert data member here
struct inputType
{
string word;
StringSet file;
};
vector<inputType> list;
public:
// Tally adds one word/file pair to the index
void tally(string word, string file);
and this is my implementation code
Code:
#include "inverted_index.h"
#include "osdir.h"
// InvertedIndex::tally
// Pre: a word and file pair as strings
// Post: adds the file to the index under word
void InvertedIndex::tally(string word, string file)
{
inputType input;
list.push_back( input );
}
// print
// Pre: an index structure
// Post: renders the index on the screen
void InvertedIndex::print()
{
for( vector<inputType>::const_iterator output = list.begin(); output != list.end(); output++ )
cout << "Word: " << output->word << "\t\tFile: " << output->file << endl;
}
and the main code
Code:
#include "inverted_index.h"
int main()
{
// test the InvertedIndex
InvertedIndex idx;
idx.tally("cat", "cats.txt");
idx.tally("cat", "animals.txt");
idx.tally("cat", "everything.txt");
idx.tally("dog", "dogs.txt");
idx.print();
why the output is empty. ??
-
can someone please help on this serioes problem of mine????anyone?