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

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值