1 Star 0 Fork 0

郑玉强/dataStructure

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
seq_list_algorithm.hpp 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
#ifndef SEQ_LIST_ALGORITHM_HPP
#define SEQ_LIST_ALGORITHM_HPP
#include "seq_list.hpp"
// 求并集
// 结果存放在seq_list_a中
template <typename TData>
void seqListUnion(SeqList<TData>& seq_list_a, SeqList<TData>& seq_list_b)
{
int a_length = seq_list_a.length();
int b_length = seq_list_b.length();
for (int i = 1; i <= b_length; i++)
{
TData list_b_item;
seq_list_b.getData(i,list_b_item);
int pos = seq_list_a.search(list_b_item);
if (pos == 0) // a中没有b
{
bool res = seq_list_a.insert(a_length,list_b_item);
if (!res)
cout << "请给seq_list_a扩容" << endl;
else
a_length++;
}
}
}
// 求交集
// 结果存放在seq_list_a中
template <typename TData>
void seqListInterSection(SeqList<TData>& seq_list_a,SeqList<TData>& seq_list_b)
{
int a_length = seq_list_a.length();
int iter_pos = 1;
while (iter_pos <= a_length)
{
TData list_a_item;
seq_list_a.getData(iter_pos, list_a_item);
int pos = seq_list_b.search(list_a_item);
if (pos == 0)
{
seq_list_a.remove(iter_pos,list_a_item);
a_length--;
}
else
{
iter_pos++;
}
}
}
#endif // !SEQ_LIST_ALGORITHM_HPP
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zheng-yuqiang_lyg_cn/data-structure.git
git@gitee.com:zheng-yuqiang_lyg_cn/data-structure.git
zheng-yuqiang_lyg_cn
data-structure
dataStructure
dev01

搜索帮助