⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sort.cpp

📁 C++Primer中文版 第三版 深入系列 Primer 第三版 著 中中文文版版潘爱民张丽译 Addison-Wesley 中国电力出版社 www.infopower.com.cn S
💻 CPP
字号:
#include <string>
using std::string;

typedef int (*PFI2S)( const string &, const string & );

int lexicoCompare( const string &, const string & );

void sort( string *s1, string *s2,
           PFI2S compare = lexicoCompare )
{
    // stopping condition for recursion
    if ( s1 < s2 ) {
        string elem = *s1;
        string *low = s1;
        string *high = s2 + 1;

        for (;;) {
            while ( compare( *++low, elem ) < 0 && low < s2) ;
            while ( compare( elem, *--high ) < 0  && high > s1) ;

            if ( low < high )
                low->swap(*high);
            else break;
        }  // end, for(;;)

        s1->swap(*high);
        sort( s1, high - 1 );
        sort( high + 1, s2 );
    } // end, if ( s1 < s2 )
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -