[Notes] algorithm - all kinds of "odd kinky tricks" (continually updated)

  This is not a long time to maintain a blog, mainly in the maintenance hexo. But in the process of preparing pat will organize ideas should be put here. If you have time, then the contents of the hexo move over. This blog is a summary of some of the main acm / pat common technique, commonly used functions, etc., met will add to the mix, it should be continuously updated until the pat grade to get good results now.

sort

The basic format sort function is: sort (first element address, the end address +1 elements, comparison function CMP)

Here is the application of the comparison function. If you write a comparison function, the default from small to large. At this time, following its comparison function (the default element type int):

BOOL CMP ( int a, int b) 
{ 
    return a <b // understood to put a in front of b       
}

For descending order, then the above read function cmp:

BOOL CMP ( int a, int b) 
{ 
    return a> b // understood to put a in front of b       
}

This function is really powerful place is that it can change the data type of comparison. To structure, student achievement as an example:

BOOL CMP (A Stu, Stu B) 
{ 
      IF (a.score = b.score!) return a.score> b.score; // score descending order 
      the else  return strcmp (a.id, b.id) < 0 ; // ticket in ascending order    
}

Is such a general principle, this function can solve most basic scheduling problem.

Guess you like

Origin www.cnblogs.com/xiejiekun/p/10969449.html