Hi, Everyone!
How could I make sure that nine values (from 0 to N) are all different
without writing too many loops? I am not afraid of statistical
parameters (e.g. coefficient of variation, etc.)
Thank You Very Much.
Truly Yours, Simon Dexter 7 1471 si******@yahoo.com wrote: Hi, Everyone!
How could I make sure that nine values (from 0 to N) are all different without writing too many loops? I am not afraid of statistical parameters (e.g. coefficient of variation, etc.)
Thank You Very Much.
Truly Yours, Simon Dexter
What's wrong with loops? With only 9 values you wouldn't be taking that
much of a performance hit to start with the first value, compare it to
the remaining 8, then the 2nd value, remaining 7, etc.
If that's not acceptable though, I'm sure you can find some built in
algorithms to test for uniqueness of values.
unique seems like a good STL candidate, however, you'd have to have
your values in a sorted container in order to use it.
Josh Mcfarlane wrote: unique seems like a good STL candidate, however, you'd have to have your values in a sorted container in order to use it.
A sorted container isn't needed. All that's needed is a sequence that's
sorted.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
<si******@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com... Hi, Everyone!
How could I make sure that nine values (from 0 to N) are all different without writing too many loops? I am not afraid of statistical parameters (e.g. coefficient of variation, etc.)
Thank You Very Much.
Truly Yours, Simon Dexter
Use a set
What is STL (concerning my question)?
On 18 Jul 2005 19:51:44 -0700, si******@yahoo.com did courageously
avow: What is STL (concerning my question)?
It is the C++ Standard Template Library the compile vendor supplies
with your compiler. It is the place for generic everything,
containers, iterators for containers, algorithms. If you're asking
that question be ready for some heady stuff.
Ken Wilson
"Coding, coding, over the bounding main()"
Actually, it is only two loops, and the complexity is n*n. Write a
function that receives your array. If you do not want to to change the
array, make a local one and copy your array to it.
Now, do a selection sort, but return at any time when the test for
equality of items in the array is true.
Suppose you return 0 on equality, otherwise return 1 at end of function
when sort completes, meaning all elements are different.
The test could look like this:
if (a[i] == a[j]) return 0;
else if (a[i] > a[j]) do-selection-sort
and if you never returned from inside the loops (the equality), now
return 1.
Hope it helps.
Regards,
Dr. Z.
Chief Scientist zo****@ZHMicro.com http://www.zhmicro.com http://distributed-software.blogspot.com
Actually, it is only two loops, and the complexity is n*n. Write a
function that receives your array. If you do not want to to change the
array, make a local one and copy your array to it.
Now, do a selection sort, but return at any time when the test for
equality of items in the array is true.
Suppose you return 0 on equality, otherwise return 1 at end of function
when sort completes, meaning all elements are different.
The test could look like this:
if (a[i] == a[j]) return 0;
else if (a[i] > a[j]) do-selection-sort
and if you never returned from inside the loops (the equality), now
return 1.
Hope it helps.
Regards,
Dr. Z.
Chief Scientist zo****@ZHMicro.com http://www.zhmicro.com http://distributed-software.blogspot.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven T. Hatton |
last post by:
This is something I've been looking at because it is central to a currently
broken part of the KDevelop new application wizard. I'm not complaining
about it being broken, It's a CVS images. ...
|
by: trickish |
last post by:
In my main I try to get values assigned to "int *thisSoduko" through
the static method Reader::read.
int main(char *args)
{
...
int *thisSoduko = new int;
if(Reader::read( fileName,...
|
by: José Joye |
last post by:
I have to compare 2 byte and I must be sure that they are fully identic.
I have to perform this check about 1000 times per minute and on arrays that
are between 100-200K in size.
In that sense,...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm trying to move a matlab program into c language. For those who knows
matlab, this is the line I want to program in c:
hx(1:nx,1:ny) = 0; % nx=10, ny=10
It works on a 2-dimensional...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: assgar |
last post by:
Hi
Developemnt on win2003 server. Final server will be linux
Apache,Mysql and PHP is being used.
I use 2 scripts(form and process).
The form displays multiple dynamic rows with chechboxs,...
|
by: tshad |
last post by:
How do you easily make a copy of an arraylist?
If you do:
arrayList2 = arrayList1
You get a pointer so that if you clear arrayList2 (arrayList2.Clear) -
arrayList1 is also cleared.
I...
|
by: zzw8206262001 |
last post by:
Hi,I find a way to make javescript more like c++ or pyhon
There is the sample code:
function Father(self) //every contructor may have "self"
argument
{
self=self?self:this; ...
|
by: Michael B Allen |
last post by:
I like to use limit pointers as sentinels when working on buffers
of data. Meaning I use ptr < lim where ptr and lim are both pointers
rather than n 0 to determine if it is safe to proceed writing...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |