C/C++ ソートの比較関数
C/C++ ソート
ソートの比較関数
qsort と STL algorithm 比較関数は異なるが、STL algorithm の各ソート比較関数は共通で利用可能。ソートテストで使用した関数サンプル
※このサンプルは、main_sort.cpp をメインとして分割(分割コンパイル)された一部。メイン、ヘッダー、共通関数等は、分割コンパイルの頁を参照。
fn_comp.cpp
//#include <iostream> //#include <time.h> //#include <string> //#include <vector> //#include <algorithm> //using namespace std; #include "main_sort.h" // ----------------------------------------- // STL sort algorithm 用 比較関数 // ----------------------------------------- // o01_sort -> sub_sort_o01.cpp // qsort -> sub_sort_qst.cpp // 修正前の STL 用比較関数 int ss1cmp(const int& a, const int& b) { return b > a; } bool ss2cmp::operator()(const int& a, const int& b) const { return b > a; } // 修正(追加)後の比較関数 int asc1_cmp(const int& a, const int& b) { return a < b; } int des1_cmp(const int& a, const int& b) { return a > b; } bool asc2_cmp::operator()(const int& a, const int& b) const { return a < b; } bool des2_cmp::operator()(const int& a, const int& b) const { return a > b; }※ここでは、STL algorithm の各比較関数(共通)のみ記述している。qsort 用は、qsort 専用なので sub_sort_qst.cpp へ併合。別途準備したソート関数 o01_sort は、qsort の比較関数を使えるようにしているが、そもそも如何にでもなるので、やはり、sub_sort_o01.cpp へ併合。
▲上へ [ 編集 ]
リンク
内部リンク
- C/C++ C++/CLI C# 関連
- VC++ 2005 Express のインストール
- C/C++ の簡単なプログラム例
- C/C++ ソート(並べ替え)
- C/C++ テストの実行
- C/C++ STL(Standard Template Library)
- 変数・定数
- プログラムの分割/ダイナミックリンクライブラリ など
- その他
- C/C++ その他::書式文字/ESC code など
- VB2005リファレンス(覚え書き)
- SQL文:SQLステートメント
- VBA(VisualBasic for Applications)
外部リンク
- 現在ありません
▲上へ [ 編集 ]
2008年07月21日(月) 15:39:16 Modified by cafeboy1