5、stack、queue、priority_Queueテンプレートパラメータタイプ演算子カスタムタイプの優先順位キューの再ロードとは

2534 ワード

stackとqueue:一端のみ操作可能
stack
 
emplace
改良版のinsert
empty
スタックを空にする
pop
宿屋を出る
push
インスタック
size
スタック内の要素の数を表示
top
スタックトップ要素の取得
swap
スタックを2つ交換
 
最も重要なのは二叉木の層順遍歴です
https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
キューによるスタックの実装
https://leetcode-cn.com/problems/implement-stack-using-queues/
ツリーのレイヤ平均
https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/
使用する
 
 
priority_queue
実は山と小さな山です
最上位要素に対する最大値---デフォルトのless--->は比較より小さい
小さなスタック------スタックトップ要素が最小---採用した比較はgreaterが比較より大きい
下部は動順表です
template ,
class Compare = less > class priority_queue;
テンプレートのパラメータ
class T 
このパラメータがテンプレート内のデータ型のパラメータです
class Container = vector
テンプレートにデータを格納するコンテナで、デフォルトのタイプはvetorです.
class Compare = less > class priority_queue;
ここでは、保存された比較方法です.デフォルトはless比較法です.-->作成されたのは山です.
 
 
デフォルトのヒープ
priority_queue q1;
たい積
priority_queue q2(v.begin(), v.end());
小さな山
priority_queue , greater> q3(v.begin(), v.end());
#include 

#include   777



using namespace std;

class Data{

public:

    Data(int year = 2019, int month = 5, int day =  18)

         :_year(year)

         , _month(month)

         , _day(day)

    {}

    bool operator  q1;

    vector v{ 3, 4, 6, 3, 5, 2, 0, 8 };

    priority_queue q2(v.begin(), v.end());

    priority_queue , greater>  q3(v.begin(), v.end());

#endif

    Data d1(2019, 6, 27);

    Data d2(2019, 6, 28);

    Data d3(2019, 6, 29);

    Data d4(2019, 6, 30);

    priority_queue, compare>  q(Less);

        //           

        //explicit priority_queue (const Compare& comp =  Compare(),

        //                             const Container&  ctnr = Container());

    q.push(&d1);

    q.push(&d2);

    q.push(&d3);

    q.push(&d4);

    system("pause");

    return 0;

}



//      :
// typedef bool(*compare)(const Data* pleft, const Data*  pRight);      compare*      

        Data*、    vector、   cmppare
テンプレートパラメータのリストはすべてタイプです
 
 
 
bool operator
return _day < d._day;//プライベートメンバー変数はクラス外では使用できません.クラスでのみ使用できます.