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