批量前移list中指定的元素
来源:互联网 发布:mac怎么压缩rar 编辑:程序博客网 时间:2024/05/16 18:35
批量选中list列表中的元素,进行移位,可用于批量选中图层进行上下移动的操作。
//将list中指定的元素向前移动一位(由lstMove指定);void moveItem(const std::list<int>& lstMove, std::list<int>& lstAll){if (lstMove.empty()) return;std::list<int>::const_iterator _lstMoveBegin = lstMove.begin();std::list<int>::const_iterator _lstMoveEnd = lstMove.end();//记录已处理的元素个数;int iCount = 0;int iSum = lstMove.size();//指定元素在队首的无需移位;std::list<int>::iterator itr = lstAll.begin();for (;itr != lstAll.end();++itr){if(_lstMoveEnd == std::find(_lstMoveBegin, _lstMoveEnd, *itr)) break;if(++iCount == iSum) return;}//处理需要移位的元素;//此时迭代器itr为第一个非指定元素;std::list<int>::iterator itrMove = itr;std::list<int>::iterator itrNext = ++itr;for (;itrNext != lstAll.end(); itrMove = itrNext++){if(_lstMoveEnd == std::find(_lstMoveBegin, _lstMoveEnd, *itrNext)) continue;//交换元素值(迭代器不改变);std::swap(*itrMove, *itrNext);if(++iCount == iSum) return;}}
阅读全文
0 0
- 批量前移list中指定的元素
- 删除List中指定元素
- java中指定删除list对应元素
- PHP中如何获得数组中指定元素的前一个或后一个元素
- C#中,取List中指定List元素
- 删除vector中指定的元素
- java取集合中指定的元素
- 删除数组中指定的元素
- 如何删除数组中指定的元素
- 删除map容器中指定的元素
- Leetcode019--删除数组中指定的元素
- js删除json中指定的元素
- 删除链表中指定的元素
- list -- set方法——替换列表中指定位置的元素
- leetcode Remove Linked List Elements 移除链表中指定元素
- Remove Linked List Elements 删除链表中指定元素
- 找出有序元素数组中指定元素出现的次数
- 批量删除数据库字段中指定的字符串
- php中正则表达式详解
- 夜神,逍遥,天天连接AS
- Nginx配置文件详解
- ElasticSearch(map数据类型)Java api 增(批量)删改查(全字段、高亮)
- webpack构建工具安装
- 批量前移list中指定的元素
- 简述 synchronized 和 java.util.concurrent.locks.Lock 的异同 ?
- 二进制中1的个数
- 基于eclipse的android开发环境配置
- C51中断函数格式
- 简单LinuxC程序关于逆序一个中英混合字符串
- 2017.7.14 流水帐系列
- 【LectCode】513. Find Bottom Left Tree Value
- 函数实现两个数的和,不能用+等算术运算符