Questions tagged [custom-compare]
26 questions
1
vote
0 answers
Sorting a map by it's element in value which is pair using C++
How do I write custom sorting for map with such attributes --
map > Valuedensity
I want to sort with
sort(Valuedensity.begin(),Valuedensity.end(),myfn(int, pair))
But I do not how to define this myfn() such that it…

Mohit Kumar
- 500
- 6
- 24
1
vote
2 answers
How to ignore "-" and "." characters in a value during sort comparison?
I have an html page that has a field that can be sorted. I also have created a javascript function that can sort that field in order. Let's imagine p_cSort is the 'id' name of that field.
function change_sort(neworder) {
…

Arty
- 819
- 3
- 13
- 24
0
votes
1 answer
Q1 : priority_queue "come before means output last", Q2 : custom compare with sort and priority_queue
Q1
https://en.cppreference.com/w/cpp/container/priority_queue
i'm looking this webpage and in template parameters section Compare says like this.
But because the priority queue outputs largest elements first, the
elements that "come before" are…

신승빈
- 347
- 3
- 10
0
votes
1 answer
Custom compare class not working as I expect for pointers to a user defined class in a std::set container
I can't figure out why in this code example the std::set container is not ordering the Entities as I expect on the basis of the compare class I defined. Anyone can help me please? Thanks
#include
#include
class Entity {
…

Nicholas Redi
- 47
- 5
0
votes
0 answers
Why does this simple custom-comparator for vector-of-vector produces a crash?
The following code crashes when I call std::sort on the bks (vector of vectors) of form [20000][3].
It seems the comparator compBks() is getting called on v1 of size 0 and v2 of size 3 after 20000 calls to compBks have been made, which could cause…

Joe Black
- 625
- 6
- 19
0
votes
0 answers
Custom comparator for a priority queue without defining a nested class
I have a class called getout (no constructor). Within that class I have some private variables that are priority queues. The priority queues are initialized with a custom comparator function that I am supposed to create:
priority_queue

Camille Burke
- 37
- 8
0
votes
1 answer
Custom comparator of Java priority queue
I am trying to sort a priority queue based on custom Comparators but it throws an error:
Line 11: error: no suitable method found for sort(Queue,>)
The priority queue is used to sort a custom class object; I am…

RobinHood
- 33
- 1
- 8
0
votes
1 answer
Overload custom comparator to std::map
I am trying to solve this problem. I came up with this solution:
typedef unordered_map stockDictType;
class StockTicker {
class Comparator {
public:
inline bool operator() (const string &a, const string &b) const {
…

Quirk
- 1,305
- 4
- 15
- 29
0
votes
2 answers
iPhone contacts app styled indexed table view implementation
My Requirement:
I have this straight forward requirement of listing names of people in alphabetical order in a Indexed table view with index titles being the starting letter of alphabets (additionally a search icon at the top and # to display misc…

KSH
- 43
- 1
- 5
-1
votes
2 answers
Collections.sort does not change list
I have a list of games that I wish to sort by the number of scores they have (in descending order). I wrote this code for this purpose;
public void OnResponse(Object response) {
List games = (List)response;
…

Filip Mattsson
- 33
- 3
-3
votes
1 answer
c++ std::find custom comparator doesn't work
I am learning how to use std::find with custom comparator now.
However, by following the guidance on-line, I am facing a compiler error.
Link to my code.
Below is my code:
#include
#include
#include
…

jiyi
- 101
- 9