• <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() {}             //默認(rèn)構(gòu)造函數(shù)
            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 //員工類(lèi)構(gòu)造函數(shù)
            22 employee::employee(long eID, string e_Name, float e_Salary)
            23 : ID(eID), name(e_Name), salary(e_Salary) {}
            24 
            25 //用于對(duì)Set容器排序的函數(shù)對(duì)象
            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 //定義一個(gè)元素類(lèi)型為employee、按KeyComp排序的Set容器類(lèi)型
            37 typedef set<employee, KeyComp> EMPLOYEE_SET;
            38 //定義MultiSet容器的隨機(jī)訪問(wèn)迭代器類(lèi)型
            39 typedef set<employee, KeyComp>::iterator EMPLOYEE_IT;
            40 //定義MultiSet容器的反向迭代器類(lèi)型
            41 typedef set<employee, KeyComp>::reverse_iterator EMPLOYEE_RIT;
            42 
            43 //函數(shù)功能:正向輸出Set容器對(duì)象的所有元素
            44 //參數(shù):一個(gè)Set容器對(duì)象
            45 //返回值:無(wú)
            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 //函數(shù)功能:逆向輸出Set容器對(duì)象的所有元素
            57 //參數(shù):一個(gè)Set容器對(duì)象
            58 //返回值:無(wú)
            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;           //聲明一個(gè)容器對(duì)象
            72  
            73  //下面的三條語(yǔ)句分別構(gòu)造三個(gè)employee對(duì)象,然后插入MultiSet容器對(duì)象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  //注意下面的兩條語(yǔ)句,因?yàn)槭荢et,不允許有重復(fù)的值,所以?xún)蓚€(gè)employee對(duì)象只會(huì)有一條加入到Set容器
            79  employees.insert(EMPLOYEE_SET::value_type(103"jiahui"12000));
            80  employees.insert(EMPLOYEE_SET::value_type(103"jiahui"12000));
            81 
            82  //正向和逆向輸出Set容器對(duì)象的所有元素
            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容器對(duì)象employees是否為空? " << (employees.empty() ? "TRUE" : "FALSE"<< endl;
            92  cout << "Set容器對(duì)象employees共有" << employees.size() << "個(gè)employee對(duì)象!" << endl;
            93 
            94  return 0;
            95 }

            posted on 2009-02-09 16:48 混沌的云 閱讀(689) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(1)

            隨筆檔案

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            一本综合久久国产二区| 久久天天躁狠狠躁夜夜不卡 | 国内精品九九久久久精品| 九九精品99久久久香蕉| 久久综合九色综合欧美狠狠| 久久艹国产| 国内精品人妻无码久久久影院导航 | 欧美激情精品久久久久久久| 国内精品久久久久久久久电影网 | 久久午夜综合久久| 狼狼综合久久久久综合网| 99久久国产综合精品网成人影院 | 久久久国产打桩机| 777久久精品一区二区三区无码| 青青久久精品国产免费看| 99久久综合狠狠综合久久止| 欧美性猛交xxxx免费看久久久| 成人综合伊人五月婷久久| 香蕉久久夜色精品国产2020| 婷婷久久综合九色综合98| 亚洲香蕉网久久综合影视| 久久影视国产亚洲| 精品久久久久久国产牛牛app| 久久亚洲AV成人无码国产| 久久人与动人物a级毛片| 九九久久精品国产| 国产成人精品久久一区二区三区av | 精品国产婷婷久久久| 国产成人久久AV免费| 精品综合久久久久久97| 久久伊人中文无码| 久久国产成人| 久久丝袜精品中文字幕| 精品无码久久久久久国产| 国产成人99久久亚洲综合精品| 一本色道久久88加勒比—综合| 狠狠狠色丁香婷婷综合久久五月 | 7777久久久国产精品消防器材| 中文字幕亚洲综合久久菠萝蜜| 久久影院亚洲一区| 日韩欧美亚洲综合久久影院Ds |