English 中文(简体)
采用平等()、限定()病媒<complex <double>>
原标题:Using equal(),find() on a vector<complex <double> >

这是一件简单直截了当的事情,但我ve着我的头目试图理解。 I m试图比较<条码>查询器和带;complex <double> > vec with a complex <double>num toeck if num have on vec. 如果没有增加。 我尝试使用平等()和算法,但没有成功。 是否有任何人知道这样做的快路?

<<>strong>EDIT2: 我不想这样作,因为复杂数字是简化的,因为我还需要在结构上开展同样的行动:

struct thing{
 int i;
 int j;
 complex <double> pos;
}typedef t_thing;

complex <double> new_num(2.0,2.0);
t_thing will_insert;
will_insert.i = 1;
will_insert.j = 1;
will_insert.pos = new_num;
vector<t_thing> vec_thing;
if(! (find(vec_thing.begin(),vec_thing.end(),will_insert) == vec_thing.end())){
  vec_thing.push_back(will_insert);
}else { 
 cout<<"element already on vec_thing"<<endl;
}

EDIT3: I ve overloaded themente=,但发现不能与以下方面合作:

: error: no matching function for call to ‘find(__gnu_cxx::__normal_iterator<thing*, std::vector<thing, std::allocator<thing> > >, __gnu_cxx::__normal_iterator<thing*, std::vector<thing, std::allocator<thing> > >, t_thing&)’
最佳回答

<代码>std: 平等算法用于比较2个代数范围。 因此,你将利用这一方法比较2个病媒,以了解这两个病媒是否含有相同的要素。

如果你只需要检查病媒内是否有单一元素,那么你只能使用<条码>std:find。

if (std::find(vec.begin(), vec.end(), std::complex<double>(1,1)) == vec.end()) {
   /* did not find element */
}
else { /* found the element */ }

但请注意,<代码>已成: 轨道并不特别适合像此那样的检索算法,因为每次研究都会使你O(N)复杂。 您不妨考虑使用<代码>std:set,这样,你们就能够发现研究的标志性复杂性,并自动保证你不会有任何重复因素。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签