如何计算用C两组之间的差异? [英] How to calculate difference between two sets in C?

查看:144
本文介绍了如何计算用C两组之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组,比如说A和B | A | = 8,| B | = 4。我想计算的差集A-B。我该如何进行?请注意,有在任一组的无重复的元素

I have two arrays, say A and B with |A|=8 and |B|=4. I want to calculate the set difference A-B. How do I proceed? Please note that there are no repeated elements in either of the sets.

编辑:非常感谢你对每个人都优雅的解决方案无数。由于我在我的项目的原型阶段,现在我实现告诉Brian和欧文最简单的解决方案。但我AP preciate巧妙地运用数据结构的建议在这里所剩下的你,即使我不是计算机科学家,而是一个工程师,从来没有学过的数据结构为一个疗程。看起来它是关于时间,我真的应该开始阅读CLRS我一直在拖延一段时间了:)再次感谢!

Thank you so much everybody for a myriad of elegant solutions. Since I am in prototyping stage of my project, for now I implemented the simplest solution told by Brian and Owen. But I do appreciate the clever use of data structures as suggested here by the rest of you, even Though I am not a computer scientist but an engineer and never studied data structures as a course. Looks like it's about time I should really start reading CLRS which I have been procrastinating for quite a while :) Thanks again!

推荐答案

迭代A的每个元素,如果每个这些元素都没有在B,然后将它们添加到一个新的集合C。

Iterate over each element of A, if each of those elements are not in B, then add them to a new set C.

这篇关于如何计算用C两组之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆