STL list查找、删除、结构体实例化对象排序

来源:互联网 发布:网络通信工程师 编辑:程序博客网 时间:2024/05/01 08:34
#include<map>#include <list>#include<iostream>#include<iterator>#include<algorithm>#include <Windows.h>using namespace std;typedef struct _tagFMItemInfo {BYTE nIndex;      //该项频点在预存列表中的索引float fFM_Preq;   //该项FM频点值_tagFMItemInfo(BYTE byIndex, float fPreq){nIndex = byIndex;fFM_Preq = fPreq;}}FMItemInfo;typedef struct _tagAMItemInfo {BYTE nIndex;      //该项频点在预存列表中的索引UINT nAM_Preq;   //该项AM频点值_tagAMItemInfo(BYTE Index, UINT nPreq){nIndex = Index;nAM_Preq = nPreq;}}AMItemInfo;class Cmpare{public:BOOL operator()(const FMItemInfo Item1, const FMItemInfo Item2) const{return (Item1.fFM_Preq < Item2.fFM_Preq);}BOOL operator()(const AMItemInfo Item1, const AMItemInfo Item2) const{return (Item1.nAM_Preq < Item2.nAM_Preq);}};int main(){list<FMItemInfo> FMItem;FMItem.clear();FMItem.push_back(FMItemInfo(1, 87.9));FMItem.push_back(FMItemInfo(7, 108.0));FMItem.push_back(FMItemInfo(4, 102.0));FMItem.push_back(FMItemInfo(6, 88.0));FMItem.push_back(FMItemInfo(9, 93.2));FMItem.push_back(FMItemInfo(12, 97.8));FMItem.push_back(FMItemInfo(10, 101.1));FMItem.push_back(FMItemInfo(2, 105.7));FMItem.sort(Cmpare());list<AMItemInfo> AMItem;AMItem.clear();AMItem.push_back(AMItemInfo(12, 559));AMItem.push_back(AMItemInfo(2, 1024));AMItem.push_back(AMItemInfo(5, 999));AMItem.push_back(AMItemInfo(1, 624));AMItem.push_back(AMItemInfo(8, 998));AMItem.push_back(AMItemInfo(4, 759));AMItem.push_back(AMItemInfo(10, 903));AMItem.push_back(AMItemInfo(11, 888));AMItem.sort(Cmpare());typedef list<int> Mylist;typedef list<int>::iterator Myiter;Mylist nList;Myiter it;nList.clear();nList.push_back(102);nList.push_back(762);nList.push_back(990);nList.push_back(56);nList.push_back(106);nList.push_back(778);nList.push_back(102);nList.sort();it = find(nList.begin(), nList.end(), 990);if (it != nList.end()){nList.erase(it);}nList.remove(102);return 0;}

0 0