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

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

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

2007-01-23 Thread Mike Polyakov
std::set 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 all th

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 Comp

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,

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::set here? Repeated inserts of the same > > >value will be ignored. > > > > True, but

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,

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::set here? Repeated inserts of the same > > >value will be ignored. > > > > True, but that will use extra memory.

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::set 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 ex

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::set 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 array

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 #include #include #include #include using namespace std; int main() { srand(time(NULL)); vector array;// original array vector unique;

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 #include #include #include #include using nam

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 Виталий Ищенко
В Вск, 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 so

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 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 thin

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 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. > > > > > > > > I was thinking the same thing. > > I think it's our du

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: Thi

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. > > > > > > > > > I was thinking the same thing. >

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. > > > > > 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-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 .. > > > > c

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 c

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 t

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 (the