Re: help with C algorythm (find unique value in an array) could you please make changes

2007-02-07 Thread Kamaraju Kusumanchi
On Monday 05 February 2007 16:51, you wrote: Kamaraju Kusumanchi wrote: [snip] 2. In the worst case, your algorithm scales as O(N^2). If I am not wrong, you can do this in O(N log(N)) steps. If your N is large (say 1000) this has a huge benefit. The algorithm would be One can do that

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Roberto C. Sanchez
On Mon, Jan 22, 2007 at 11:36:18PM -0500, Mike Polyakov wrote: Michael, Why not just use a std::setint here? Repeated inserts of the same value will be ignored. True, but that will use extra memory. Since pointers are iterators, this can be done on ordinary array in place without extra

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Jeronimo Pellegrini
Hi. On Tue, Jan 23, 2007 at 06:01:34AM -0500, Roberto C. Sanchez wrote: On Mon, Jan 22, 2007 at 11:36:18PM -0500, Mike Polyakov wrote: Michael, Why not just use a std::setint here? Repeated inserts of the same value will be ignored. True, but that will use extra memory. Since

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Wim De Smet
On 1/22/07, Ron Johnson [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/22/07 08:12, Roberto C. Sanchez wrote: On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote: On Sun, Jan 21, 2007 at

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Paul E Condon
this is really a reply to Mike: On Tue, Jan 23, 2007 at 06:01:34AM -0500, Roberto C. Sanchez wrote: On Mon, Jan 22, 2007 at 11:36:18PM -0500, Mike Polyakov wrote: Michael, Why not just use a std::setint here? Repeated inserts of the same value will be ignored. True, but that will

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Roberto C. Sanchez
On Tue, Jan 23, 2007 at 12:22:14PM -0700, Paul E Condon wrote: Nicolai M. Josuttis, The C++ Standard Library, covers all this and much more. It is expensive, but perhaps you can find a copy at a nearby university library. This is an awesome book. A couple of years ago, I broke down, and

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/23/07 13:38, Roberto C. Sanchez wrote: On Tue, Jan 23, 2007 at 12:22:14PM -0700, Paul E Condon wrote: [snip] If you program in C++ at all, these three books are a must have. Even if you don't program in C++, if you program at all Code

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Mike Polyakov
std::setint does _not_ waste memory. Paul, Yes, but I didn't say it wasted memory. I said it would use extra memory, since the original problem was posed as finding unique values in an array, I assume you are given an array of values up front with which to work with. In this case, inserting

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-23 Thread Roberto C. Sanchez
On Tue, Jan 23, 2007 at 01:58:06PM -0600, Ron Johnson wrote: On 01/23/07 13:38, Roberto C. Sanchez wrote: On Tue, Jan 23, 2007 at 12:22:14PM -0700, Paul E Condon wrote: [snip] If you program in C++ at all, these three books are a must have. Even if you don't program in C++, if you program

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Jon Dowland
On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote: On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote: This smells like CompSci homework. g I was thinking the same thing. I think it's our duty to provide the most cunning/evil solution possible then :) --

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Roberto C. Sanchez
On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote: On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote: This smells like CompSci homework. g I was thinking the same thing. I think it's our

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/22/07 08:12, Roberto C. Sanchez wrote: On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote: On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote: This smells

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Kamaraju Kusumanchi
On Monday 22 January 2007 05:30, Jon Dowland wrote: On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote: On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote: This smells like CompSci homework. g I was thinking the same thing. I think it's our duty to provide

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Roberto C. Sanchez
On Mon, Jan 22, 2007 at 11:36:11AM -0500, Kamaraju Kusumanchi wrote: Hey guys Lighten up! Give him the benefit of doubt and help him if you can. May be the OP belongs to some other field and is trying to get a sense of algorithm implementation for a related problem. Except that: *

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Jon Dowland
On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: I think it's our duty to provide the most cunning/evil solution possible then :) Probably not all that evil or cunning by most people's standards, but here's my solution. I tried to do a continuation-passing-style tail recursive

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/22/07 11:22, Jon Dowland wrote: On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: [snip] /* populate the unique list */ for(i = 1; i argc; ++i) { int val = atoi(argv[i]); if(!in_list(val, list)) {

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Виталий Ищенко
В Вск, 21/01/2007 в 19:13 -0500, Kamaraju Kusumanchi пишет: 2. In the worst case, your algorithm scales as O(N^2). If I am not wrong, you can do this in O(N log(N)) steps. If your N is large (say 1000) this has a huge benefit. The algorithm would be a. use a quicksort technique to sort

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Jon Dowland
On Mon, Jan 22, 2007 at 11:42:32AM -0600, Ron Johnson wrote: On 01/22/07 11:22, Jon Dowland wrote: On Mon, Jan 22, 2007 at 10:30:29AM +, Jon Dowland wrote: [snip] /* populate the unique list */ for(i = 1; i argc; ++i) { int val = atoi(argv[i]);

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Mike Polyakov
No you're quite right, not least since my insertion routine traverses the whole list on each call. I didn't write this for speed of execution, merely speed of writing it :) For speed of writing, here's the whole thing in C++ using STL: #include vector #include algorithm #include iostream

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Michael Marsh
On 1/22/07, Mike Polyakov [EMAIL PROTECTED] wrote: For speed of writing, here's the whole thing in C++ using STL: #include vector #include algorithm #include iostream #include cstdlib #include ctime using namespace std; int main() { srand(time(NULL)); vectorint array;

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-22 Thread Mike Polyakov
Michael, Why not just use a std::setint here? Repeated inserts of the same value will be ignored. True, but that will use extra memory. Since pointers are iterators, this can be done on ordinary array in place without extra memory. Only thing is that unique() function modifies the original

help with C algorythm (find unique value in an array) could you please make changes

2007-01-21 Thread Jabka atu
Good evening to all,... i wrote a small algorythm (in C ) to find how many uniqe value are in an array .. then change the size of the array to store all the unique values .. code you please look at the code and make changes to it (to) /* This program Should find the true length of an array

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-21 Thread Kamaraju Kusumanchi
On Sunday 21 January 2007 18:18, Jabka atu wrote: Good evening to all,... i wrote a small algorythm (in C ) to find how many uniqe value are in an array .. then change the size of the array to store all the unique values .. Couple of comments: 1. Your code is working fine for me. Though the

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-21 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/21/07 17:18, Jabka atu wrote: Good evening to all,... i wrote a small algorythm (in C ) to find how many uniqe value are in an array .. then change the size of the array to store all the unique values .. code you please look at the code

Re: help with C algorythm (find unique value in an array) could you please make changes

2007-01-21 Thread Roberto C. Sanchez
On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote: On 01/21/07 17:18, Jabka atu wrote: Good evening to all,... i wrote a small algorythm (in C ) to find how many uniqe value are in an array .. then change the size of the array to store all the unique values .. code you