Find an entry of in a matrix of vector C++

I want find the element v[0][0]=1 v[0][1]=2 of the vector v with the use of lambda function and find of stl. #include <iostream> #include <algorithm> using namespace std; int main() { vector<vector<int>> v(3); v[0].r...
more »

2017-08-12 19:08 (1) Answers

Using a predicate to sort according to size

I understood that a predicate takes argument from an input range of iterators and does operations as intended, but when we supply a binary predicate and a pair of iterators, how does it work? How are the elements of a container passed to the predicat...
more »

2017-08-11 22:08 (3) Answers

Modify sorted array or sort the array everytime?

Problem: Given an array of size N, print the sorted sub sets of size K with consecutive elements. N = 10, K = 4 8 4 7 5 1 10 3 9 2 6 Output: 4 5 7 8, 1 4 5 7, 1 5 7 10, 1 3 5 10, ... Approach 1: Sort all the sub sets and print. Complexity Analy...
more »

2017-05-04 08:05 (3) Answers

insert into std::map using class method

I searched a lot for this issue, but didn't find anything, so sorry if it's duplicate. I have a problem with inserting into std::map using class method which returns *this. If i try to insert more values, only the first one is actually inserted. Let...
more »

2017-04-27 18:04 (3) Answers

Why there is no std::sort(vector<T>&)

When sorting a vector in C++ you can use STL as: std::sort(vec.begin(), vec.end()); As this is very common usage (i.e. providing begin and end iterator) I wonder why there is no sort overload which would accept a reference to the vector e.g: temp...
more »

2017-02-22 04:02 (1) Answers

STL sorting in nested data structure

this is STL based data structure that I created for representing graph in C++. typedef std::pair<int,int> ii; typedef std::vector<ii> vii; typedef std::vector< vii > graph; in Kruskal algorithm that I read in Steven Halim's (Comp...
more »

2017-01-30 13:01 (1) Answers

C++ sort cannot sort set of strings?

I am wondering how I can sort a set that contains strings. For example, I have a set: std::set<std::string> setA = {"B","A","C"} Then I wanna use this to do the sorting: std::sort(setA.begin(),setA.end()); But the C++ compiler cannot let ...
more »

2017-01-01 17:01 (3) Answers

Difference between f and &f

Consider the code: void f(int) {} int main() { std::function<void(int)>func = f; func(3); std::function<void(int)>funcc = &f; funcc(3); void(*ptr)(int) = f; ptr(3); void(*ptrr)(int) = &f; ptrr(3)...
more »

2016-12-25 10:12 (0) Answers

Java Sorting while reading

So I'm a C++ programmer student, and I'm starting to learn Java, and I would like to read a class called Candidate with two string values (Name and ID), and I would like to store these Candidates in a container. What would be the best container to u...
more »

2016-12-21 19:12 (6) Answers

Sort a matrix defined as a vector<double>

Assume I have a square matrix A of size n, defined as a std::vector<double>. std::vector<double> A(n*n); The elements of the matrix are accessed the usual way: double a_ij = A[i*n + j]; I need to sort the rows of the matrix in ascen...
more »

2016-11-03 10:11 (3) Answers

c++ std::map class with generic key

I have a family of classes, and each subclass needs a map but the keys will have different types, although they both will perform the exact same operations with the map. Also the value on both cases will be string. So far I have code similar to the e...
more »

2016-11-01 23:11 (3) Answers

Three.js prevent seeing file in resources

When user click to specific 3Dmodel I get it from server render and display in browser using three.js. Some of models are free and some of them has a price. The problem comes when user click to model which is not free - and in fact he can go to conso...
more »

2016-10-04 11:10 (1) Answers