# Pragma once # include <windows. h> class ccell {public: rect; public: ccell (); ccell (rect RC );~ Ccell (void); int getleft () const; // obtain the X coordinate int gettop () const in the upper left corner; // obtain the Y coordinate in the upper left corner };
#include "StdAfx.h"#include "Cell.h"CCell::CCell(){}CCell::CCell(RECT rc){rect = rc;}CCell::~CCell(void){}int CCell::GetLeft() const{return rect.left;}int CCell::GetTop() const{return rect.top;}
// Sort. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include" cell. H "# include <list >#include <iostream> using namespace STD; Class cmpare1 {public: bool operator () (const ccell cell1, const ccell cell2) const ;}; bool cmpare1: Operator () (const ccell cell1, const ccell cell2) const {If (cell1.gettop () = cell2.gettop () {return cell1.getleft () <cell2.getleft (); // front of the rectangle X coordinate smaller} elsereturn cell1.gettop () <cell2.gettop (); // front of the rectangle y coordinate smaller} class CMP Are {public: bool operator () (const rect RC1, const rect RC2) const ;}; bool cmpare: Operator () (const rect RC1, const rect RC2) const {If (rc1.top = rc2.top) {return rc1.left <rc2.left; // front of the rectangle X coordinate smaller} elsereturn rc1.top <rc2.top; // before the Y coordinate of the rectangle} int _ tmain (INT argc, _ tchar * argv []) {rect RC1 = {1, 2, 4}; rect RC2 = {2, 1, 3, 4}; rect RC3 = {3, 2, 3, 4}; rect RC4 = {2, 2, 3, 4}; // RC2 <RC1 <RC4 <rc3ccell cell1 (RC1); ccell Cell 2 (RC2); ccell cell3 (RC3); ccell cell4 (RC4); // STD: List <rect> rlist; // rlist. push_back (RC1); // rlist. push_back (RC2); // rlist. push_back (RC3); // rlist. push_back (RC4); // rlist. sort (cmpare (); STD: List <ccell> clist; clist. push_back (cell1); clist. push_back (cell2); clist. push_back (cell3); clist. push_back (cell4); clist. sort (cmpare1 (); // STD: List <rect >:: iterator ITER; // For (iter = rlist. begin (); iter! = Rlist. end (); ITER ++) /// {// cout <ITER-> left <ITER-> top <ITER-> right <ITER-> bottom <Endl; //} STD :: list <ccell>: iterator ITER; For (iter = clist. begin (); iter! = Clist. end (); ITER ++) {cout <ITER-> rect. left <ITER-> rect. top <ITER-> rect. right <ITER-> rect. bottom <Endl;} return 0 ;}