hash tables and 2d vectors

Posted by Sunil on Stack Overflow See other posts from Stack Overflow or by Sunil
Published on 2011-01-04T17:45:13Z Indexed on 2011/01/04 17:53 UTC
Read the original article Hit count: 125

Filed under:
|
|

I want to push a 2d vector into a hash table row by row and later search for a row (vector) in the hash table and want to be able to find it. I want to do something like

#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main(){

std::set < vector<int> > myset;

vector< vector<int> > v;

int k = 0;

for ( int i = 0; i < 5; i++ ) {
 v.push_back ( vector<int>() );

for ( int j = 0; j < 5; j++ )
 v[i].push_back ( k++ );
}

for ( int i = 0; i < 5; i++ ) {
  std::copy(v[i].begin(),v[i].end(),std::inserter(myset)); // This is not correct but what is the right way ?

// and also here, I want to search for a particular vector if it exists in the table. for ex. the second row of vector v.

}

  return 0;
}

I'm not sure how to insert and look up a vector in a set. So if nybody could guide me, it will be helpful. Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector