vector

challenge: optimize unlisting [easy]

Because SO is a bit slow lately, I'm posting an easy question. I would appreciate it if big fishes stayed on the bench for this one and give rookies a chance to respond. Sometimes we have objects that have a ridiculous amount of large list elements (vectors). How would you "unlist" this object into a single vector. Show proof that your ...

change of vectors first pointer

hello, when i use vector to store some data, i usually access to this data by the pointer of the vector's first entry. because it it faster than the at() method. but i realize that when i insert a block of data, say an array to the end of vector, the first entry's pointer changes. this may be realated to stack stuff, but if i add the ar...

How to get all columns smaller than a threshold?

I have a row-vector with arbitrary values. I am interested in the column IDs of the columns which contain a value <= a specified threshold the number of columns which lie below the threshold. Is there a more elegant way to compute this in MATLAB than using a for-loop? ...

Vector math -- finding vector of 2 points?

Reviewing for midterm, need some help with the following: Given the points p0 = [1 0] and p1 = [4 6] write the implicit equation for a line in vector form (i.e. compute the appropriate v and n). Is the point p2 = [1.5 3] on the line or above or below the line? What is the equation for a plane with the norman n = [5 3 4] going through t...

Java Vector: How to find out the would-be index of an item

Hello, I would like to do the following in Java: I have an element, and I would like to know what would be its index had it been inserted into a collection of other objects (given they're already sorted). So if I have a vector of ints like this: 1,3,5,7,9 and I had the int '2' in hand, I'd know that its 'would-be' index is i=1, between...

Pointers to objects in a set or in a vector - does it matter?

Hi, just came a across a situation where I needs to store heap-allocated pointers (to a class B) in an STL container. The class that owns the privately held container (class A) also creates the instances of B. Class A will be able to return a const pointers to B instances for clients of A. Now, does it matter if these pointer are stor...

Changing things from a vector

What is the easiest way to take something out of an vector and changes its values? This isn't working the way I expected. for(int i = 0; i < list.size(); i++) { someType s = list.at(i); s.x = 10; s.y = 20; s.z = 30; } However, when I go to print out the x,y,z of that someType s, it doesn't give me what I expect. Sorry I am mixing up ...

Find delta angle to use for rotation given entity with position, initial rotation and target point to 'face toward'

Hi, I'm coding a flocking algorithm in Java but I'm stuck at a certain point (using the Ardor3D libraries, in a 2D plane). Basically, I need to find the angle difference to add to the current rotation. If you can only get the way it should be pointing with polar coordinates with 0 degs at north and not the difference, not to worry -- I ...

Is it possible to iterate an mpl::vector at run time without instantiating the types in the vector?

Generally, I would use boost::mpl::for_each<>() to traverse a boost::mpl::vector, but this requires a functor with a template function declared like the following: template<typename T> void operator()(T&){T::staticCall();} My problem with this is that I don't want the object T to be instantiated by for_each<>. I don't need the T parame...

Calculating angular rate.

Hi, I'm simulating a physical object, using a mass spring system. By means of deltas and cross products, I can easily calulate the up, forward and side vectors. I want to calculate what the angular rate (how fast it's spinning), for the object space X, Y and Z axis. Calculating the world space angle first won't help, since I need the a...

How do I check against all vector elements?

This compiles and runs ok on Visual C++ 2010 Express but it only checks against the [2] element: "Fish". int main() { vector<string> words; string temp; vector<string> disliked(3); disliked[0] = "Broccoli"; disliked[1] = "Mushrooms"; disliked[2] = "Fish"; while (cin >> temp) ...

passing a 2 dimensional vector to a function

Hi Guys, How to pass a 2 dimensional Vector to a function in CPP ? I saw the examples for 1 dimension but not for 2 dimensions. If it is passed, is it passed by value or by reference ? vector< vector<int> > matrix1(3, vector<int>(3,0)); //Matrix Declaration. printMatrix(&matrix1); // Function call void printMatrix(vector< vector<int...