partition a vector of vectors

This is a discussion on partition a vector of vectors within the C++ Programming forums, part of the General Programming Boards category; hi, I am working in this problem, where I have a set of N d-dimensional points, e.g. (4,5,6,8) (2,0,4,6), are ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    28

    partition a vector of vectors

    hi,

    I am working in this problem, where I have a set of N d-dimensional points, e.g. (4,5,6,8) (2,0,4,6), are 4-d points, which I have stored in a vector of vectors.

    I am trying to partition the vector of vectors according to the median value of one the dimensions.

    I tried to use the stl partition method like this:
    Code:
    // S is a vector of vectors containing the points
    vector < vector <int> >::iterator iter;
    vector < vector <int> >::iterator pos_beg = S.begin();
    vector < vector <int> >::iterator pos_end = S.end();
    
    iter = partition (pos_beg, pos_end, bind2nd( is_less(d),median)  );
    
    
    // "is_less" is a class I use to sort the vector of vectors according to an arbitraty dimension.
    // e.g. sort(S.begin(), S.end(), is_less(d));
    class is_less  {
      public:
        is_less(const int index = 0): i(index) {}
        bool operator()(const vector<int>& v1, const vector<int>& v2) {
            return v1[i] < v2[i];
        }
      private:
        const int i;
     };
    Unfortunately, it doesn't work, (or compile correctly). It seems that I have a problem with the predicate of the partition method; the bind2nd function I saw it in an example, but it worked there for just a common vector, and does not seem to work in this case.

    Would anyone know how I might solve this problem with the partition.

    thanks
    Last edited by acosgaya; 10-06-2006 at 11:24 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    I believe your operator() should be const.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disk Partition Stuff
    By CodeMonkey in forum Tech Board
    Replies: 15
    Last Post: 12-19-2008, 10:53 AM
  2. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  3. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  4. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  5. hardware interaction in c
    By vineetwadwekar in forum C Programming
    Replies: 6
    Last Post: 03-29-2002, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21