# spnsp

6 questions

0

44

views

### Iterate vector of pairs

I have vector1 [1,2,5,4,7]. I have another vector2 [(1,1),(2,5),(3,6),(4,7)]. I want to check if the element in Vector1 is the first or second element in the pair vector2. this is the code snippet. Any better approach other than this which takes less time ? std::vector vector1; std::vector vector2;...
spnsp

1

127

views

### Which boost library should i use to add the intervals as mentioned in the description?

I am working on intervals in a c++ program. I want something like below: I want to add intervals iteratively in a for loop. Assume my first interval is (0, 5). I want to add an interval (3,6) such that the resulting interval set should be (0,3), (3,6). If my third interval added is (4,7), my resulti...
spnsp

1

112

views

### Adding vertex in graph using boost as the elements of a vector

I have a vector say [3,2,1,8,7]. The vertices of the Graph should be 3,2,1,8,7. How can i create this in a loop. Can i use add_vertex function of boost in a loop which iterates through this vector ? Or which is the best way to add these vector elements as the vertices of the graph ? This is what i h...
spnsp

2

86

views

### Random number generation from a vector of numbers

I have a vector v = {1,5,4,2}. Now I want to write a function that returns a random pair of numbers from this vector. Example: {1,2},{4,4},{2,5},{5,1},{1,5},{2,2}....... I want this pair to be generated in a random manner. Any idea how to implement this ?
spnsp

1

317

views

### Directed Acyclic Graph : Updating the vertex property of a parent node by comparing the property of the child nodes.

I have the connections between nodes in a DAG like this. 1 --> 7 2 --> 3 --> 4 5 4 --> 6 5 --> 6 --> 7 --> I have to perform some tasks on this graph. 1) Find all the vertices without successors. 2) Assign a value to the vertices without successors. (I can do this with Vertex properties). 3) Back...
spnsp

1