• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 20,  comments - 6,  trackbacks - 0
             1 #include <iostream>
             2 #include <assert.h>
             3 #include <set>
             4 #include <string>
             5 using namespace std;
             6 
             7 struct employee
             8 {
             9 //Member Function
            10 public:
            11  employee() {}             //默認構造函數
            12  employee(long eID, string e_Name, float e_Salary);
            13 
            14 //Attribute
            15 public:
            16  long ID;                  //Employee ID
            17  string name;              //Employee Name
            18  float salary;           //Employee Salary
            19 };
            20 
            21 //員工類構造函數
            22 employee::employee(long eID, string e_Name, float e_Salary)
            23 : ID(eID), name(e_Name), salary(e_Salary) {}
            24 
            25 //用于對Set容器排序的函數對象
            26 class KeyComp
            27 {
            28 public:
            29  bool operator() (const employee& A, const employee& B)
            30  {
            31   return (A.salary < B.salary);
            32  }
            33 };
            34 
            35 
            36 //定義一個元素類型為employee、按KeyComp排序的Set容器類型
            37 typedef set<employee, KeyComp> EMPLOYEE_SET;
            38 //定義MultiSet容器的隨機訪問迭代器類型
            39 typedef set<employee, KeyComp>::iterator EMPLOYEE_IT;
            40 //定義MultiSet容器的反向迭代器類型
            41 typedef set<employee, KeyComp>::reverse_iterator EMPLOYEE_RIT;
            42 
            43 //函數功能:正向輸出Set容器對象的所有元素
            44 //參數:一個Set容器對象
            45 //返回值:無
            46 void output_set(EMPLOYEE_SET e)
            47 {
            48  assert(!e.empty());
            49  EMPLOYEE_IT it;
            50  for (it = e.begin(); it != e.end(); it++)
            51  {
            52   cout << (*it).ID << '\t' << (*it).name << '\t' << (*it).salary << endl;
            53  }
            54 }
            55 
            56 //函數功能:逆向輸出Set容器對象的所有元素
            57 //參數:一個Set容器對象
            58 //返回值:無
            59 void reverse_output_set(EMPLOYEE_SET e)
            60 {
            61  assert(!e.empty());
            62  EMPLOYEE_RIT rit;
            63  for (rit = e.rbegin(); rit != e.rend(); rit++)
            64  {
            65   cout << (*rit).ID << '\t' << (*rit).name << '\t' << (*rit).salary << endl;
            66  }
            67 }
            68         
            69 int main(int argc, char* argv[])
            70 {
            71  EMPLOYEE_SET employees;           //聲明一個容器對象
            72  
            73  //下面的三條語句分別構造三個employee對象,然后插入MultiSet容器對象employees
            74  employees.insert(EMPLOYEE_SET::value_type(100"huahua"20000));
            75  employees.insert(EMPLOYEE_SET::value_type(101"jiafeng"8000));
            76  employees.insert(EMPLOYEE_SET::value_type(102"guangli"10000));
            77 
            78  //注意下面的兩條語句,因為是Set,不允許有重復的值,所以兩個employee對象只會有一條加入到Set容器
            79  employees.insert(EMPLOYEE_SET::value_type(103"jiahui"12000));
            80  employees.insert(EMPLOYEE_SET::value_type(103"jiahui"12000));
            81 
            82  //正向和逆向輸出Set容器對象的所有元素
            83  assert(!employees.empty());
            84  cout << "From Head To Tail:" << endl;
            85  output_set(employees);
            86 
            87  cout << "From Tail To Head:" << endl;
            88  reverse_output_set(employees);
            89 
            90 
            91  cout << "Set容器對象employees是否為空? " << (employees.empty() ? "TRUE" : "FALSE"<< endl;
            92  cout << "Set容器對象employees共有" << employees.size() << "個employee對象!" << endl;
            93 
            94  return 0;
            95 }

            posted on 2009-02-09 16:48 混沌的云 閱讀(689) 評論(0)  編輯 收藏 引用
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            国产精品狼人久久久久影院| 久久精品桃花综合| 色综合久久中文综合网| 久久93精品国产91久久综合| 久久久久久久精品妇女99| 性欧美丰满熟妇XXXX性久久久 | 99久久亚洲综合精品网站| 久久久久亚洲精品男人的天堂| 久久国产免费直播| 91精品国产91热久久久久福利| 久久亚洲精品国产亚洲老地址| 高清免费久久午夜精品| 亚洲国产日韩欧美综合久久| AV无码久久久久不卡网站下载| 日本精品久久久久影院日本 | 亚洲AV无码久久精品成人| 99久久99久久精品国产| 久久精品国产第一区二区三区| 亚洲伊人久久综合影院| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品这里热有精品| 久久久久亚洲AV片无码下载蜜桃| 国内精品久久九九国产精品| 东方aⅴ免费观看久久av| 久久亚洲精品无码观看不卡| 狠狠色丁香婷婷综合久久来| 午夜欧美精品久久久久久久| 亚洲精品tv久久久久久久久久| 99精品伊人久久久大香线蕉| 久久九九有精品国产23百花影院| 99久久人妻无码精品系列| 久久青青草原精品国产| 久久久久久久久久久久中文字幕| 99久久精品免费看国产一区二区三区| 欧美亚洲日本久久精品| 久久天天躁狠狠躁夜夜2020| 国产亚洲色婷婷久久99精品91 | 狠狠精品久久久无码中文字幕| 国产精品久久久久久一区二区三区 | 精品久久久久中文字| 国产亚洲精久久久久久无码AV|