Re: Efficient Vector Comparison
- From: user923005 <dcorbit@xxxxxxxxx>
- Date: Thu, 28 Jun 2007 15:48:56 -0700
On Jun 28, 1:48 am, Yao Qi <qiyao...@xxxxxxxxx> wrote:
In our program, we will compare every two vectors. In current
implementation, we compare every element of that vector until we get the
comparison result. It is not any more efficient way to do this?
b.t.w the length of vector is variable.
Do you have to sort the vectors?
Why not something simple like:
#include <vector>
#include <iostream>
using namespace std;
int main(void)
{
vector < double > a;
vector < double > b;
a.resize(100);
b.resize(100);
size_t index;
for (index = 0; index < 100; index++)
{
a[index] = (double)index;
b[index] = (double) index;
if (index == 99) b[index]+=1.0;
}
if (a < b)
cout << "a is less than b" << endl;
else if (a > b)
cout << "a is greater than b" << endl;
else
cout << "a is equal to b" << endl;
return 0;
}
.
- Follow-Ups:
- Re: Efficient Vector Comparison
- From: Yao Qi
- Re: Efficient Vector Comparison
- References:
- Efficient Vector Comparison
- From: Yao Qi
- Efficient Vector Comparison
- Prev by Date: Re: The software I wish I had
- Next by Date: Re: Efficient Vector Comparison
- Previous by thread: Re: Efficient Vector Comparison
- Next by thread: Re: Efficient Vector Comparison
- Index(es):