One 、 Press key Sort

  1.map Order ( The little one is in front , The big one is behind ):

  map<float,string,less<float> > m_aSort;// has float Sort from small to large

  2.map Reverse order ( The big one is ahead , The small one is behind ):

  map<float,string,greater<float> > m_aSortR;// has float Sort from large to small

  

   notes :  

    use greater_equal(less_equal) Do the third parameter to sort ,map Of find The function fails .

    If you need to store the same key It's worth it Key value pair , It can be used multimap, See :https://www.cnblogs.com/SZxiaochun/p/10482964.html

struct SIndexData
{
string sCode;
int iDate;
int iTime;
float f1;
SIndexData():
iDate(0),
iTime(0)
{
} bool operator == (const SIndexData & obj) const
{
return sCode == obj.sCode && iDate == obj.iDate && iTime == obj.iTime;
} bool operator < (const SIndexData & obj) const
{
return iDate < obj.iDate ;
}
}; map<float, SIndexData, greater_equal<float> > m_is; SIndexData sIndexData1;
sIndexData1.sCode = "000001";
sIndexData1.iDate = 20171025;
sIndexData1.iTime = 94000;
sIndexData1.f1 = 7.8f;
m_is[sIndexData1.f1] = sIndexData1; SIndexData sIndexData2;
sIndexData2.sCode = "000002";
sIndexData2.iDate = 20171025;
sIndexData2.iTime = 94000;
sIndexData2.f1 = 7.9f;
m_is[sIndexData2.f1] = sIndexData2; SIndexData sIndexData3;
sIndexData3.sCode = "000004";
sIndexData3.iDate = 20171025;
sIndexData3.iTime = 94000;
sIndexData3.f1 = 7.8f;
//m_is[sIndexData3.f1] = sIndexData3;
m_is.insert(make_pair(sIndexData3.f1, sIndexData3)); SIndexData sIndexData4 = m_is[sIndexData3.f1]; map<float, SIndexData, greater_equal<float> >::iterator iter = m_is.find(sIndexData3.f1);
if (iter != m_is.end())
{
cout << "find succ" << endl;
}
else
{
cout << "find error" << endl;
} getchar();

For cause analysis, please refer to :https://www.cnblogs.com/Harley-Quinn/p/7247978.html

Two 、 Press value Sort

typedef pair<int, string> PAIR;

bool CmpByValue(const PAIR & lhs, const PAIR & rhs)
{
return lhs.second < rhs.second; // Press value Sort from small to large . If value It's not the basic type (int、short etc. ), It's a self defined structure , Just in the structure < Operator ( See :http://www.cnblogs.com/SZxiaochun/p/6377084.html The first 41 That's ok ).
} map<int,string> m_two; m_two[1] = "xiaochun";
m_two.insert(make_pair(2,"chunxiao")); vector<PAIR> vPair;
vPair.insert(vPair.end(), m_two.begin(), m_two.end()); sort(vPair.begin(), vPair.end(), CmpByValue);

  

map positive sequence 、 More articles on reverse order

  1. C# Sort of array ( Positive order and negative order )

    C# Sort of array ( Positive order and negative order ) This sort of sorting Super simple ! using System; using System.Collections.Generic; using System.Linq; using ...

  2. oracle positive sequence The reverse Sort query

    positive sequence : From small to large order by t.id asc The reverse : From big to small order by t.id desc

  3. c - The reverse / Positive order output per .

    #include <stdio.h> #include <math.h> /* Determine the number of digits of a positive integer , And in the positive order , Output their bits in reverse order . */ int invert(int); vo ...

  4. Comparable Interface learning : To the object List Compare and sort ( Positive and negative order )

    Comparable There is only one interface int compareTo(T o) Method 1.int compareTo(T o) Method Method statement : Compare this object with the specified object , If this object is larger than , be equal to , Less than the specified object , ...

  5. Java The order of choice ( positive sequence 、 The reverse )

    public class SelectSort { public static void main(String[] args) { /** * @author JadeXu * @// TODO: ...

  6. C++ Sorting function sort(),qsort() The meaning and usage of , character string string In reverse order, etc

    In school, we learned a lot of sorting algorithms , But in the c++stl It also encapsulates sort Such as function , The header file is #include <algorithm> Function name Function description sort Sort all elements of a given interval st ...

  7. Creation of linked list 、 Length measurement 、 Sort 、 Insert 、 The realization of reverse order (C Language )

    #include <stdio.h> #define END_elem 0 struct node { int date; struct node * next; }; // Linked list creation no ...

  8. C Language list full operation ( increase , Delete , Change , check , The reverse , Incremental sort , Descending sort , Chain queues , Chain stack )

    One , data structure —— Full operation of linked list : List form : among , Every node (Node) It's a structure , This structure contains data fields , Pointer to the domain , Data fields are used to store data , The pointer field is used to point to the next node : In particular : For single chain table , Every node (Nod ...

  9. 【 Abnormal needs 】bootstrapTable Column sorting - Select positive order reverse order not sort

    The product manager : that table Can you click the next option to select positive order and reverse order ? -- That's bootstrapTable Plug in for ! I won't support it ! It can't be changed !! Be careful : Fake data , The effect is http Request parameters for brain compensation This is a boot ...

Random recommendation

  1. CRM Data key forget Solution

    UPDATE EmailServerProfile SET IncomingPassword=nullUPDATE EmailServerProfile SET OutgoingPassword=nu ...

  2. 1125MySQL Sending data Detailed analysis of problems that lead to slow query

    -- problem 1 tablename Using a primary key index is better than idx_ref_id The reason for the slow EXPLAIN SELECT SQL_NO_CACHE COUNT(id) FROM dbname.tbname FORC ...

  3. In depth analysis @Transactional Usage of

    key word : Business , Programming transactions , Declarative transactions .spring Business management .AOP Transaction enhancement .@Transactional In the analysis, in-depth analysis @Transactional Before using , Let's first review some of the basics of business . ...

  4. React Basic grammar learning

    React Mainly as follows 3 Characteristics : As UI(Just the UI) fictitious DOM(Virtual DOM): This is the highlight yes React One of the most important features Put it in memory The least updated view , Update of difference part diff Algorithm ...

  5. l Implementation of interrupt

    from :http://blog.chinaunix.net/uid-25014876-id-90740.html xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  6. session And cookie The difference between

    session     session The working mechanism of : Create a unique id (UID), And based on this UID To store variables .UID Stored in cookie in , Or by URL To conduct .   ...

  7. python Operator —— Logical operators

    not An order is a reverse order , The real becomes the fake , Fake becomes real (True Is true ,False It's fake ) b = Trueprint(not b) It was true , But added “not” The command becomes a fake ,not Instructions are unary operators , ...

  8. Scala aggregate Map

    stay scala in Map Divided into variable length (mutable) And immutable length (immutable) /** * Immutable length map Once the length is initialized , You can't make changes */ // Create... By means of arrows map val map = ...

  9. Account book wechat small program development 4

    Learn to add components Integrated date component Add the component Need to be in main.js In file , Make a statement data value date And wxml Medium {{date}} Binding Association , And then in onLoad Initializes the date value in string format , To process the date component, click OK ...

  10. 【Java Basics 】15、 The binary representation of negative numbers

    In the computer , A negative number is expressed as a complement to its positive value . What is complement ? This has to come from the original , The irony is that . Original code : An integer , Binary number converted by absolute value size , It's called the original code . such as 00000000 00000000 00000000 ...